Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Mateusz Pawlik
ted-datasets
Commits
926c6bd0
Commit
926c6bd0
authored
Oct 23, 2018
by
Mateusz Pawlik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sort_dataset.sh made stand-alone tool and included into pipelines of bolzano and sentiment.
parent
8d28fda0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
5 deletions
+37
-5
bolzano/download_prepare.sh
bolzano/download_prepare.sh
+2
-1
sentiment/download_prepare.sh
sentiment/download_prepare.sh
+1
-1
utilities/sort_dataset.sh
utilities/sort_dataset.sh
+34
-3
No files found.
bolzano/download_prepare.sh
View file @
926c6bd0
...
@@ -32,7 +32,8 @@ unzip bolzano-address-trees.zip -d original_data
...
@@ -32,7 +32,8 @@ unzip bolzano-address-trees.zip -d original_data
# - remove header
# - remove header
# - remove IDs
# - remove IDs
# - sort by number of nodes (equivalent to number of "{")
# - sort by number of nodes (equivalent to number of "{")
iconv
-f
ISO-8859-1
-t
"UTF-8"
original_data/L.trees |
tail
-n
+14 |
sed
's/.*://'
|
awk
'{print gsub("{","{"), $0}'
|
sort
-n
|
cut
-d
' '
-f2-
>
bolzano_sorted.bracket
iconv
-f
ISO-8859-1
-t
"UTF-8"
original_data/L.trees |
tail
-n
+14 |
sed
's/.*://'
|
\
../utilities/sort_dataset.sh
>
bolzano_sorted.bracket
# Tidy up.
# Tidy up.
rm
bolzano-address-trees.zip
rm
bolzano-address-trees.zip
...
...
sentiment/download_prepare.sh
View file @
926c6bd0
...
@@ -35,7 +35,7 @@ unzip trainDevTestTrees_PTB.zip -d original_data
...
@@ -35,7 +35,7 @@ unzip trainDevTestTrees_PTB.zip -d original_data
# - sort by number of nodes (equivalent to number of "{")
# - sort by number of nodes (equivalent to number of "{")
iconv
-f
ISO-8859-1
-t
"UTF-8"
original_data/trees/dev.txt original_data/trees/train.txt |
\
iconv
-f
ISO-8859-1
-t
"UTF-8"
original_data/trees/dev.txt original_data/trees/train.txt |
\
sed
-e
's/(/{/g'
|
sed
-e
's/)/}/g'
|
sed
-E
's/[[:space:]]([{])/\1/g'
|
\
sed
-e
's/(/{/g'
|
sed
-e
's/)/}/g'
|
sed
-E
's/[[:space:]]([{])/\1/g'
|
\
awk
'{print gsub("{","{"), $0}'
|
sort
-n
|
cut
-d
' '
-f2-
>
sentiment_sorted.bracket
../utilities/sort_dataset.sh
>
sentiment_sorted.bracket
# Tidy up.
# Tidy up.
rm
trainDevTestTrees_PTB.zip
rm
trainDevTestTrees_PTB.zip
...
...
utilities/sort_dataset.sh
View file @
926c6bd0
#!/bin/bash
#!/bin/bash
# | sort by number of nodes (equivalent to number of "{"), remove duplicates
# The MIT License (MIT)
# cat $1 | perl -F{ -lane 'print "$#F $_"' | sort -n | cut -d' ' -f2- > "${1%.bracket}_sorted.bracket"
# Copyright (c) 2017 Thomas Hütter, Mateusz Pawlik.
cat
$1
|
awk
'{print gsub("{","{")-gsub("\\\\{","\\{"), $0}'
|
sort
-n
|
cut
-d
' '
-f2-
>
"
${
1
%.bracket
}
_sorted.bracket"
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# The script accepts input from file or stdin in case a file is not given.
# Solution taken from:
# https://superuser.com/questions/747884/how-to-write-a-script-that-accepts-input-from-a-file-or-from-stdin
[
$#
-ge
1
-a
-f
"
$1
"
]
&&
input
=
"
$1
"
||
input
=
"-"
# Sort the trees in the input file by the number of nodes which is equivalent
# to the number of open bracket characters "{".
#
# NOTE: We substract the escaped brackets because they're part of node labels.
#
cat
$input
|
awk
'{print gsub("{","{")-gsub("\\\\{","\\{"), $0}'
|
sort
-n
|
\
cut
-d
' '
-f2-
# > "${1%.bracket}_sorted.bracket"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment