-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_test_rels.sh
More file actions
executable file
·59 lines (48 loc) · 2.02 KB
/
extract_test_rels.sh
File metadata and controls
executable file
·59 lines (48 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
if [ "$#" -ne 1 ]; then
echo "Extract and format event instances for select predicates with document timestamp"
echo "Usage: extract_test_rels.sh <news_gen.json>"
exit 1
fi
mkdir -p temporal_rels
# Step 1: identify relevant lines in the news_gen file using grep
# Step 2: extract relation strings using sed to reformat them into the output file
echo "Binary extraction"
mkdir temporal_rels/binary
PREDS=('buy' 'purchase' 'own' 'sell' 'bid\.for' 'pay\.for' 'receive' 'acquire' 'marry' 'divorce' 'travel\.to' 'move\.to' 'fly\.to' 'at' 'be\.in' 'be\.at' 'arrive\.in' 'arrive\.at' 'run\.for' 'kill' 'murder' 'play\.for' 'score\.for' 'win\.against' 'compete\.against' 'pass' 'propose')
RELS=()
for PRED in ${PREDS[@]}; do
PRED_PREFIX=$(echo $PRED | sed -r 's_(.*)\\.*_\1_')
RELS+=("\($PRED_PREFIX\.1,$PRED\.2\)")
done
PREDS+=('elect\.2\.to\.2' 'marry\.2\.to\.2')
RELS+=('\(elect\.2,elect\.to\.2\)' '\(marry\.2,marry\.to\.2\)')
for i in "${!PREDS[@]}"; do
PRED=${PREDS[$i]}
REL=${RELS[$i]}
echo $PRED ':' $REL
# grep -E "\($REL::([^:]+::){2}(GE|EG)" $1 | sed -r 's_.*date":"([^"]*)".*\(('"$REL"'[^\}]*)\)"\}.*_\1 \2_g' > "temporal_rels/binary/$PRED.txt"
grep -E "\($REL::([^:]+::){2}(GE|EG)" $1 | sed -r 's_.*date":"([^"]*)".*articleId":"([^"]*)".*\(('"$REL"'[^\}]*)\)"\}.*_\1 \3 \2_g' > "temporal_rels/binary/$PRED.txt"
echo 'finished' $PRED
done
############
echo ""
echo "Unary extraction"
mkdir temporal_rels/unary
PREDS=('die' 'be\.candidate' 'be\.dead' 'be\.guilty' 'sentence')
RELS=()
for PRED in ${PREDS[@]}; do
RELS+=("$PRED\.1")
done
PREDS_PASSIVE=('kill')
for PRED in ${PREDS_PASSIVE[@]}; do
PREDS+=("$PRED\.2")
RELS+=("$PRED\.2")
done
for i in "${!PREDS[@]}"; do
PRED=${PREDS[$i]}
REL=${RELS[$i]}
echo $PRED ':' $REL
# grep -E "\($REL::[^:]+::E" $1 | sed -r 's_.*date":"([^"]*)".*\(('"$REL"'[^\}]*)\)"\}.*_\1 \2_g' > "temporal_rels/unary/$PRED.txt"
grep -E "\($REL::[^:]+::E" $1 | sed -r 's_.*date":"([^"]*)".*articleId":"([^"]*)".*\(('"$REL"'[^\}]*)\)"\}.*_\1 \3 \2_g' > "temporal_rels/unary/$PRED.txt"
echo 'finished' $PRED
done