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
47bb60a5
Commit
47bb60a5
authored
2 years ago
by
wesenberg
Browse files
Options
Downloads
Patches
Plain Diff
17.
parent
b1ee3b82
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
wesenberg/SmatchClass.py
+1
-1
1 addition, 1 deletion
wesenberg/SmatchClass.py
wesenberg/util.py
+21
-18
21 additions, 18 deletions
wesenberg/util.py
with
22 additions
and
19 deletions
wesenberg/SmatchClass.py
+
1
−
1
View file @
47bb60a5
...
...
@@ -32,7 +32,7 @@ def calc_smatch_to_r(name, source, summary, graph_source, graph_summary):
smatch_pred
=
calc_one_smatch
(
graph_source
=
graph_source
,
graph_summary
=
graph_summary
)
if
smatch_pred
[
0
]
==
0
:
if
smatch_pred
[
0
]
==
0
and
smatch_pred
[
1
]
!=
0
:
safe_smatch_error
(
name
=
name
+
"
_null
"
,
one
=
source
,
two
=
summary
,
recall
=
0
,
precision
=
None
,
smatch_pred
=
smatch_pred
,
graph_source
=
graph_source
,
graph_summary
=
graph_summary
)
...
...
This diff is collapsed.
Click to expand it.
wesenberg/util.py
+
21
−
18
View file @
47bb60a5
...
...
@@ -20,7 +20,7 @@ from wesenberg.Konstanten import LIST_SYMBOLS_TO_DELETE, ROOT_PATH, AMRLIB_PATH,
def
remove_bugs
(
sentence
):
sentence
=
remove_all_hash_for_amr
(
sentence
)
# replace with " " to find
and
between two removed chars
# replace with " " to find
" and "
between two removed chars
sentence
=
remove_single_char_for_amr
(
sentence
,
"
"
)
sentence
=
remove_minus_for_amr
(
sentence
,
"
"
)
sentence
=
remove_and_for_amr
(
sentence
)
...
...
@@ -38,7 +38,9 @@ def calc_one_amr(nlp, sentence, file_name):
else
:
output
=
strip_amr_for_smatch
(
graphs
[
0
])
except
IndexError
:
return
""
output
=
""
safe_amr_error
(
file_name
+
"
_empty
"
,
""
,
output
,
sentence
)
if
SAFE_AMR_ERROR
:
output_list
=
output
.
split
(
"
\n
"
)
...
...
@@ -48,15 +50,21 @@ def calc_one_amr(nlp, sentence, file_name):
if
item
not
in
search_list
:
search_list
.
append
(
item
)
else
:
path
=
os
.
path
.
join
(
AMR_ERROR_PATH
)
if
not
os
.
path
.
exists
(
path
):
os
.
makedirs
(
path
)
with
open
(
path
+
file_name
+
"
.txt
"
,
'
a
'
)
as
txt
:
txt
.
write
(
sentence
+
"
\n
"
+
item
+
"
\n
"
+
output
+
"
\n\n
"
)
safe_amr_error
(
file_name
,
item
,
output
,
sentence
)
break
return
output
def
safe_amr_error
(
file_name
,
item
,
output
,
sentence
):
path
=
os
.
path
.
join
(
AMR_ERROR_PATH
)
if
not
os
.
path
.
exists
(
path
):
os
.
makedirs
(
path
)
if
item
!=
""
:
item
=
"
\n
"
+
item
with
open
(
path
+
file_name
+
"
.txt
"
,
'
a
'
)
as
txt
:
txt
.
write
(
sentence
+
item
+
"
\n
"
+
output
+
"
\n\n
"
)
def
init_amr
(
stog_name
):
amrlib
.
setup_spacy_extension
()
nlp
=
spacy
.
load
(
LOAD_SPARCY
)
...
...
@@ -333,7 +341,8 @@ def calc_f_score_smatch(name, one, two, smatch_pred, graph_source, graph_summary
def
calc_precision_smatch
(
name
,
one
,
two
,
smatch_pred
,
graph_source
,
graph_summary
):
precision
=
smatch_pred
[
0
]
/
smatch_pred
[
1
]
if
1
<
precision
:
safe_smatch_error
(
name
,
one
,
two
,
None
,
precision
,
smatch_pred
,
graph_source
,
graph_summary
)
safe_smatch_error
(
name
=
name
,
one
=
one
,
two
=
two
,
result
=
precision
,
smatch_pred
=
smatch_pred
,
graph_source
=
graph_source
,
graph_summary
=
graph_summary
)
precision
=
1
return
precision
...
...
@@ -341,27 +350,21 @@ def calc_precision_smatch(name, one, two, smatch_pred, graph_source, graph_summa
def
calc_recall_smatch
(
name
,
one
,
two
,
smatch_pred
,
graph_source
,
graph_summary
):
recall
=
smatch_pred
[
0
]
/
smatch_pred
[
2
]
if
1
<
recall
:
safe_smatch_error
(
name
=
name
,
one
=
one
,
two
=
two
,
re
call
=
recall
,
precision
=
None
,
smatch_pred
=
smatch_pred
,
safe_smatch_error
(
name
=
name
,
one
=
one
,
two
=
two
,
re
sult
=
recall
,
smatch_pred
=
smatch_pred
,
graph_source
=
graph_source
,
graph_summary
=
graph_summary
)
recall
=
1
return
recall
def
safe_smatch_error
(
name
,
one
,
two
,
re
call
,
precision
,
smatch_pred
,
graph_source
,
graph_summary
):
def
safe_smatch_error
(
name
,
one
,
two
,
re
sult
,
smatch_pred
,
graph_source
,
graph_summary
):
if
SAFE_SMATCH_ERROR
:
path
=
os
.
path
.
join
(
BACKUP_SMATCH_ERROR_PATH
)
if
not
os
.
path
.
exists
(
path
):
os
.
makedirs
(
path
)
with
open
(
path
+
name
+
"
.txt
"
,
'
a
'
)
as
txt
:
if
recall
is
not
None
:
txt
.
write
(
"
one:
\t\t
"
+
one
+
"
\n
Two:
\t\t
"
+
two
+
"
\n
Recall:
\t\t
"
+
str
(
recall
)
+
"
\n
Smatch:
\t\t
"
+
str
(
smatch_pred
)
+
"
\n
Source:
\n
"
+
graph_source
+
"
\n
Summary:
\n
"
+
graph_summary
+
"
\n\n
"
)
if
precision
is
not
None
:
txt
.
write
(
"
one:
\t\t
"
+
one
+
"
\n
t
wo:
\t\t
"
+
two
+
"
\n
Precision:
\t
"
+
str
(
p
re
cision
)
+
"
\n
Smatch:
\t\t
"
+
str
(
"
one:
\t\t
"
+
one
+
"
\n
T
wo:
\t\t
"
+
two
+
"
\n
Result:
\t
\t
"
+
str
(
re
sult
)
+
"
\n
Smatch:
\t\t
"
+
str
(
smatch_pred
)
+
"
\n
Source:
\n
"
+
graph_source
+
"
\n
Summary:
\n
"
+
graph_summary
+
"
\n\n
"
)
...
...
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