Skip to content
Snippets Groups Projects
Commit c20d86f9 authored by Alice Brenon's avatar Alice Brenon
Browse files

Add the code used to annotate ENE and export labels while we're at it

parent 94929cb9
No related branches found
No related tags found
No related merge requests found
from GEODE.Metadata import articleKey, fromKey, toKey
import pandas
import sys
columns = articleKey + ['event', 'position', 'size', 'totalSize']
def eventsOfAnnotation(start, common, annotated):
rows = pandas.DataFrame([{**common,
'event': span.label_,
'position': start + span.start_char,
'size': span.end_char - span.start_char}
for span in annotated.spans['sc']])
if len(rows):
rows[columns].to_csv(sys.stdout, sep='\t', index=False, header=False)
def detector(model, corpus):
print(*columns, sep='\t')
for text in corpus.get_all():
paragraphs = text['content'].split('\n\n')
common = {**fromKey(toKey(text)),
'totalSize': sum([len(p) for p in paragraphs])}
currentPosition = 0
for paragraph in paragraphs:
eventsOfAnnotation(currentPosition, common, model(paragraph))
currentPosition += len(paragraph)
ene_labels = [
"Domain-mark",
"Head",
"Latlong",
"NC-Spatial",
"NC-Person",
"NP-Misc",
"NP-Person",
"NP-Spatial",
"Relation",
"ENE-Spatial",
"ENE-Person",
"ENE-Misc"
]
from GEODE.ENE.Detector import detector
from GEODE.Store import corpus
import spacy
import sys
detector(spacy.load(sys.argv[1]), corpus(sys.argv[2]))
(use-modules ((gnu packages machine-learning) #:select (python-pytorch python-scikit-learn)) (use-modules ((gnu packages machine-learning) #:select (python-pytorch python-scikit-learn python-spacy))
((gnu packages python-science) #:select (python-pandas)) ((gnu packages python-science) #:select (python-pandas))
((gnu packages python-xyz) #:select (python-matplotlib ((gnu packages python-xyz) #:select (python-matplotlib
python-nltk python-nltk
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
(list python-matplotlib (list python-matplotlib
python-pandas python-pandas
python-scikit-learn python-scikit-learn
python-seaborn)) python-seaborn
python-spacy))
(arguments (arguments
(list #:tests? #f)) (list #:tests? #f))
(home-page "https://gitlab.liris.cnrs.fr/geode/geopyck") (home-page "https://gitlab.liris.cnrs.fr/geode/geopyck")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment