Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rl-sentence-compression-wesenberg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wesenberg
rl-sentence-compression-wesenberg
Commits
681c18d9
Commit
681c18d9
authored
2 years ago
by
wesenberg
Browse files
Options
Downloads
Patches
Plain Diff
amr_error
parent
f42e5cde
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
wesenberg/SmatchClass.py
+2
-1
2 additions, 1 deletion
wesenberg/SmatchClass.py
wesenberg/smatch.py
+0
-864
0 additions, 864 deletions
wesenberg/smatch.py
wesenberg/util.py
+57
-2
57 additions, 2 deletions
wesenberg/util.py
with
59 additions
and
867 deletions
wesenberg/SmatchClass.py
+
2
−
1
View file @
681c18d9
from
wesenberg
import
util
,
smatch
from
wesenberg.DataAnalytics
import
DataAnalytics
from
wesenberg.DataResults
import
DataResults
from
wesenberg.util
import
get_amr_match_new
INT_SMATCH_SOURCE_SUMMARY
=
"
1
"
INT_SMATCH_GOLD_SUMMARY
=
"
2
"
...
...
@@ -58,7 +59,7 @@ def calc_one_smatch(graph_source, graph_summary):
T is the total number of triples in the first AMR
G is the total number of triples in the second AMR
"""
smatch
.
match_triple_dict
=
{}
smatch_pred
=
smatch
.
get_amr_match
(
cur_amr1
=
graph_source
,
cur_amr2
=
graph_summary
)
smatch_pred
=
get_amr_match
_new
(
cur_amr1
=
graph_source
,
cur_amr2
=
graph_summary
)
return
smatch_pred
...
...
This diff is collapsed.
Click to expand it.
wesenberg/smatch.py
deleted
100755 → 0
+
0
−
864
View file @
f42e5cde
This diff is collapsed.
Click to expand it.
wesenberg/util.py
+
57
−
2
View file @
681c18d9
from
os.path
import
exists
import
random
import
os
from
statistics
import
median
,
stdev
,
variance
import
re
...
...
@@ -11,9 +10,12 @@ import spacy
import
pickle
import
amr
from
smatch
import
get_best_match
from
wesenberg.Konstanten
import
LIST_SYMBOLS_TO_DELETE
,
ROOT_PATH
,
AMRLIB_PATH
,
\
LIST_MODEL_NAME
,
LOAD_SPARCY
,
ROUGE_TYPES
,
DIVIDER_PATH
,
BACKUP_SMATCH_ERROR_PATH
,
SAFE_SMATCH_ERROR
,
\
AMR_ERROR_PATH
,
SAFE_AMR_ERROR
,
GTOS_MODEL
AMR_ERROR_PATH
,
SAFE_AMR_ERROR
def
remove_bugs
(
sentence
):
...
...
@@ -425,3 +427,56 @@ def safe_reward_list(path, name, safe_list, step, n=-1):
tmp
+=
"
Reward:
\t\t
"
+
str
(
reward
)
+
'
\n
'
tmp
+=
'
\n
'
txt
.
write
(
tmp
)
def
get_amr_match_new
(
cur_amr1
,
cur_amr2
,
sent_num
=
1
,
justinstance
=
False
,
justattribute
=
False
,
justrelation
=
False
):
amr_pair
=
[]
for
i
,
cur_amr
in
(
1
,
cur_amr1
),
(
2
,
cur_amr2
):
try
:
amr_pair
.
append
(
amr
.
AMR
.
parse_AMR_line
(
cur_amr
))
except
Exception
as
e
:
print
(
"
Error in parsing amr %d: %s
"
%
(
i
,
cur_amr
))
print
(
"
Please check if the AMR is ill-formatted. Ignoring remaining AMRs
"
)
print
(
"
Error message: %s
"
%
e
)
amr1
,
amr2
=
amr_pair
prefix1
=
"
a
"
prefix2
=
"
b
"
# Rename node to "a1", "a2", .etc
amr1
.
rename_node
(
prefix1
)
# Renaming node to "b1", "b2", .etc
amr2
.
rename_node
(
prefix2
)
(
instance1
,
attributes1
,
relation1
)
=
amr1
.
get_triples
()
(
instance2
,
attributes2
,
relation2
)
=
amr2
.
get_triples
()
attributes1
=
list
(
set
(
attributes1
))
relation1
=
list
(
set
(
relation1
))
attributes2
=
list
(
set
(
attributes2
))
relation2
=
list
(
set
(
relation2
))
# optionally turn off some of the node comparison
doinstance
=
doattribute
=
dorelation
=
True
if
justinstance
:
doattribute
=
dorelation
=
False
if
justattribute
:
doinstance
=
dorelation
=
False
if
justrelation
:
doinstance
=
doattribute
=
False
(
best_mapping
,
best_match_num
)
=
get_best_match
(
instance1
,
attributes1
,
relation1
,
instance2
,
attributes2
,
relation2
,
prefix1
,
prefix2
,
doinstance
=
doinstance
,
doattribute
=
doattribute
,
dorelation
=
dorelation
)
if
justinstance
:
test_triple_num
=
len
(
instance1
)
gold_triple_num
=
len
(
instance2
)
elif
justattribute
:
test_triple_num
=
len
(
attributes1
)
gold_triple_num
=
len
(
attributes2
)
elif
justrelation
:
test_triple_num
=
len
(
relation1
)
gold_triple_num
=
len
(
relation2
)
else
:
test_triple_num
=
len
(
instance1
)
+
len
(
attributes1
)
+
len
(
relation1
)
gold_triple_num
=
len
(
instance2
)
+
len
(
attributes2
)
+
len
(
relation2
)
return
best_match_num
,
test_triple_num
,
gold_triple_num
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment