Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Sciencebeam Gym
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sciencebeam
Sciencebeam Gym
Commits
30199223
Commit
30199223
authored
7 years ago
by
Daniel Ecer
Browse files
Options
Downloads
Patches
Plain Diff
added abstract
parent
a5f8863b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sciencebeam_gym/inference_model/extract_to_xml.py
+10
-4
10 additions, 4 deletions
sciencebeam_gym/inference_model/extract_to_xml.py
sciencebeam_gym/inference_model/extract_to_xml_test.py
+9
-0
9 additions, 0 deletions
sciencebeam_gym/inference_model/extract_to_xml_test.py
with
19 additions
and
4 deletions
sciencebeam_gym/inference_model/extract_to_xml.py
+
10
−
4
View file @
30199223
...
...
@@ -19,9 +19,11 @@ from sciencebeam_gym.inference_model.extract_from_annotated_document import (
class
Tags
(
object
):
TITLE
=
'
manuscript_title
'
ABSTRACT
=
'
abstract
'
class
XmlPaths
(
object
):
TITLE
=
'
front/article-meta/title-group/article-title
'
ABSTRACT
=
'
front/article-meta/abstract
'
def
get_logger
():
return
logging
.
getLogger
(
__name__
)
...
...
@@ -35,7 +37,7 @@ def rsplit_xml_path(path):
def
create_node_recursive
(
xml_root
,
path
,
exists_ok
=
False
):
node
=
xml_root
.
find
(
path
)
if
node
:
if
node
is
not
None
:
if
not
exists_ok
:
raise
RuntimeError
(
'
xml node already exists: %s
'
%
path
)
return
node
...
...
@@ -49,13 +51,17 @@ def create_node_recursive(xml_root, path, exists_ok=False):
return
node
def
set_xml_text
(
xml_root
,
path
,
text
):
node
=
create_node_recursive
(
xml_root
,
path
,
exists_ok
=
False
)
node
.
text
=
text
node
=
create_node_recursive
(
xml_root
,
path
,
exists_ok
=
True
)
if
node
.
text
is
None
:
node
.
text
=
text
else
:
node
.
text
+=
'
\n
'
+
text
return
node
def
extracted_items_to_xml
(
extracted_items
):
simple_xml_mapping
=
{
Tags
.
TITLE
:
XmlPaths
.
TITLE
Tags
.
TITLE
:
XmlPaths
.
TITLE
,
Tags
.
ABSTRACT
:
XmlPaths
.
ABSTRACT
}
xml_root
=
E
.
article
()
for
extracted_item
in
extracted_items
:
...
...
This diff is collapsed.
Click to expand it.
sciencebeam_gym/inference_model/extract_to_xml_test.py
+
9
−
0
View file @
30199223
...
...
@@ -21,6 +21,7 @@ from sciencebeam_gym.inference_model.extract_to_xml import (
)
TEXT_1
=
'
some text here
'
TEXT_2
=
'
more text to come
'
class
TestExtractedItemsToXml
(
object
):
def
test_should_return_empty_xml_for_no_empty_list_of_extracted_items
(
self
):
...
...
@@ -34,6 +35,14 @@ class TestExtractedItemsToXml(object):
assert
xml_root
is
not
None
assert
get_text_content
(
xml_root
.
find
(
XmlPaths
.
TITLE
))
==
TEXT_1
def
test_should_append_to_abstract
(
self
):
xml_root
=
extracted_items_to_xml
([
ExtractedItem
(
Tags
.
ABSTRACT
,
TEXT_1
),
ExtractedItem
(
Tags
.
ABSTRACT
,
TEXT_2
)
])
assert
xml_root
is
not
None
assert
get_text_content
(
xml_root
.
find
(
XmlPaths
.
ABSTRACT
))
==
'
\n
'
.
join
([
TEXT_1
,
TEXT_2
])
class
TestMain
(
object
):
def
test_should_extract_from_simple_annotated_document
(
self
):
with
TemporaryDirectory
()
as
path
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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