opener-opinion-detector-base 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +101 -0
- data/bin/opinion-detector-base +19 -0
- data/core/annotation.cfg.erb +9 -0
- data/core/packages/KafNafParser-1.4.tar.gz +0 -0
- data/core/packages/VUA_pylib-1.5.tar.gz +0 -0
- data/core/python-scripts/LICENSE +339 -0
- data/core/python-scripts/README.md +226 -0
- data/core/python-scripts/classify_kaf_naf_file.py +499 -0
- data/core/python-scripts/cross_validation.py +634 -0
- data/core/python-scripts/generate_folds.py +134 -0
- data/core/python-scripts/models.cfg +10 -0
- data/core/python-scripts/my_templates/README +33 -0
- data/core/python-scripts/my_templates/templates_exp.only0.txt +6 -0
- data/core/python-scripts/my_templates/templates_exp.pol0.txt +10 -0
- data/core/python-scripts/my_templates/templates_exp.red.txt +7 -0
- data/core/python-scripts/my_templates/templates_exp.txt +10 -0
- data/core/python-scripts/my_templates/templates_holder.only0.txt +11 -0
- data/core/python-scripts/my_templates/templates_holder.red.txt +9 -0
- data/core/python-scripts/my_templates/templates_holder.txt +10 -0
- data/core/python-scripts/my_templates/templates_target.only0.txt +11 -0
- data/core/python-scripts/my_templates/templates_target.red.txt +9 -0
- data/core/python-scripts/my_templates/templates_target.txt +10 -0
- data/core/python-scripts/run_all_experiments.sh +49 -0
- data/core/python-scripts/run_basic.py +20 -0
- data/core/python-scripts/run_experiment.sh +42 -0
- data/core/python-scripts/scripts/__init__.py +1 -0
- data/core/python-scripts/scripts/config_manager.py +314 -0
- data/core/python-scripts/scripts/crfutils.py +215 -0
- data/core/python-scripts/scripts/extract_feats_relations.py +295 -0
- data/core/python-scripts/scripts/extract_features.py +376 -0
- data/core/python-scripts/scripts/feats_to_crf.exp.py +105 -0
- data/core/python-scripts/scripts/lexicons.py +44 -0
- data/core/python-scripts/scripts/link_entities_distance.py +77 -0
- data/core/python-scripts/scripts/relation_classifier.py +250 -0
- data/core/python-scripts/train.py +566 -0
- data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/PKG-INFO +10 -0
- data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/SOURCES.txt +22 -0
- data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/dependency_links.txt +1 -0
- data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/installed-files.txt +47 -0
- data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/top_level.txt +1 -0
- data/core/site-packages/pre_build/KafNafParser/KafNafParserMod.py +390 -0
- data/core/site-packages/pre_build/KafNafParser/KafNafParserMod.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/__init__.py +14 -0
- data/core/site-packages/pre_build/KafNafParser/__init__.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/constituency_data.py +125 -0
- data/core/site-packages/pre_build/KafNafParser/constituency_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/coreference_data.py +52 -0
- data/core/site-packages/pre_build/KafNafParser/coreference_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/dependency_data.py +78 -0
- data/core/site-packages/pre_build/KafNafParser/dependency_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/entity_data.py +59 -0
- data/core/site-packages/pre_build/KafNafParser/entity_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/external_references_data.py +41 -0
- data/core/site-packages/pre_build/KafNafParser/external_references_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/feature_extractor/__init__.py +2 -0
- data/core/site-packages/pre_build/KafNafParser/feature_extractor/__init__.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/feature_extractor/constituency.py +205 -0
- data/core/site-packages/pre_build/KafNafParser/feature_extractor/constituency.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/feature_extractor/dependency.py +309 -0
- data/core/site-packages/pre_build/KafNafParser/feature_extractor/dependency.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/features_data.py +131 -0
- data/core/site-packages/pre_build/KafNafParser/features_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/header_data.py +127 -0
- data/core/site-packages/pre_build/KafNafParser/header_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/opinion_data.py +211 -0
- data/core/site-packages/pre_build/KafNafParser/opinion_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/references_data.py +23 -0
- data/core/site-packages/pre_build/KafNafParser/references_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/span_data.py +63 -0
- data/core/site-packages/pre_build/KafNafParser/span_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/term_data.py +111 -0
- data/core/site-packages/pre_build/KafNafParser/term_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/term_sentiment_data.py +42 -0
- data/core/site-packages/pre_build/KafNafParser/term_sentiment_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/text_data.py +99 -0
- data/core/site-packages/pre_build/KafNafParser/text_data.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/PKG-INFO +10 -0
- data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/SOURCES.txt +14 -0
- data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/dependency_links.txt +1 -0
- data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/installed-files.txt +23 -0
- data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/top_level.txt +1 -0
- data/core/site-packages/pre_build/VUA_pylib/__init__.py +1 -0
- data/core/site-packages/pre_build/VUA_pylib/__init__.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/common/__init__.py +1 -0
- data/core/site-packages/pre_build/VUA_pylib/common/__init__.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/common/common.py +28 -0
- data/core/site-packages/pre_build/VUA_pylib/common/common.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/corpus_reader/__init__.py +1 -0
- data/core/site-packages/pre_build/VUA_pylib/corpus_reader/__init__.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/corpus_reader/google_web_nl.py +156 -0
- data/core/site-packages/pre_build/VUA_pylib/corpus_reader/google_web_nl.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/io_utils/__init__.py +1 -0
- data/core/site-packages/pre_build/VUA_pylib/io_utils/__init__.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/io_utils/feature_file.py +121 -0
- data/core/site-packages/pre_build/VUA_pylib/io_utils/feature_file.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/lexicon/__init__.py +1 -0
- data/core/site-packages/pre_build/VUA_pylib/lexicon/__init__.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/lexicon/lexicon.py +72 -0
- data/core/site-packages/pre_build/VUA_pylib/lexicon/lexicon.pyc +0 -0
- data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/PKG-INFO +10 -0
- data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/SOURCES.txt +7 -0
- data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/dependency_links.txt +1 -0
- data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/installed-files.txt +11 -0
- data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/top_level.txt +1 -0
- data/core/site-packages/pre_build/VUKafParserPy/KafDataObjectsMod.py +165 -0
- data/core/site-packages/pre_build/VUKafParserPy/KafDataObjectsMod.pyc +0 -0
- data/core/site-packages/pre_build/VUKafParserPy/KafParserMod.py +439 -0
- data/core/site-packages/pre_build/VUKafParserPy/KafParserMod.pyc +0 -0
- data/core/site-packages/pre_build/VUKafParserPy/__init__.py +7 -0
- data/core/site-packages/pre_build/VUKafParserPy/__init__.pyc +0 -0
- data/core/vendor/src/crfsuite/AUTHORS +1 -0
- data/core/vendor/src/crfsuite/COPYING +27 -0
- data/core/vendor/src/crfsuite/ChangeLog +103 -0
- data/core/vendor/src/crfsuite/INSTALL +236 -0
- data/core/vendor/src/crfsuite/Makefile.am +19 -0
- data/core/vendor/src/crfsuite/Makefile.in +783 -0
- data/core/vendor/src/crfsuite/README +183 -0
- data/core/vendor/src/crfsuite/aclocal.m4 +9018 -0
- data/core/vendor/src/crfsuite/autogen.sh +38 -0
- data/core/vendor/src/crfsuite/compile +143 -0
- data/core/vendor/src/crfsuite/config.guess +1502 -0
- data/core/vendor/src/crfsuite/config.h.in +198 -0
- data/core/vendor/src/crfsuite/config.sub +1714 -0
- data/core/vendor/src/crfsuite/configure +14273 -0
- data/core/vendor/src/crfsuite/configure.in +149 -0
- data/core/vendor/src/crfsuite/crfsuite.sln +42 -0
- data/core/vendor/src/crfsuite/depcomp +630 -0
- data/core/vendor/src/crfsuite/example/chunking.py +49 -0
- data/core/vendor/src/crfsuite/example/crfutils.py +179 -0
- data/core/vendor/src/crfsuite/example/ner.py +270 -0
- data/core/vendor/src/crfsuite/example/pos.py +78 -0
- data/core/vendor/src/crfsuite/example/template.py +88 -0
- data/core/vendor/src/crfsuite/frontend/Makefile.am +29 -0
- data/core/vendor/src/crfsuite/frontend/Makefile.in +640 -0
- data/core/vendor/src/crfsuite/frontend/dump.c +116 -0
- data/core/vendor/src/crfsuite/frontend/frontend.vcxproj +129 -0
- data/core/vendor/src/crfsuite/frontend/iwa.c +273 -0
- data/core/vendor/src/crfsuite/frontend/iwa.h +65 -0
- data/core/vendor/src/crfsuite/frontend/learn.c +439 -0
- data/core/vendor/src/crfsuite/frontend/main.c +137 -0
- data/core/vendor/src/crfsuite/frontend/option.c +93 -0
- data/core/vendor/src/crfsuite/frontend/option.h +86 -0
- data/core/vendor/src/crfsuite/frontend/readdata.h +38 -0
- data/core/vendor/src/crfsuite/frontend/reader.c +136 -0
- data/core/vendor/src/crfsuite/frontend/tag.c +427 -0
- data/core/vendor/src/crfsuite/genbinary.sh.in +15 -0
- data/core/vendor/src/crfsuite/include/Makefile.am +11 -0
- data/core/vendor/src/crfsuite/include/Makefile.in +461 -0
- data/core/vendor/src/crfsuite/include/crfsuite.h +1063 -0
- data/core/vendor/src/crfsuite/include/crfsuite.hpp +555 -0
- data/core/vendor/src/crfsuite/include/crfsuite_api.hpp +400 -0
- data/core/vendor/src/crfsuite/include/os.h +61 -0
- data/core/vendor/src/crfsuite/install-sh +520 -0
- data/core/vendor/src/crfsuite/lib/cqdb/COPYING +28 -0
- data/core/vendor/src/crfsuite/lib/cqdb/Makefile.am +21 -0
- data/core/vendor/src/crfsuite/lib/cqdb/Makefile.in +549 -0
- data/core/vendor/src/crfsuite/lib/cqdb/cqdb.vcxproj +86 -0
- data/core/vendor/src/crfsuite/lib/cqdb/include/cqdb.h +524 -0
- data/core/vendor/src/crfsuite/lib/cqdb/src/cqdb.c +587 -0
- data/core/vendor/src/crfsuite/lib/cqdb/src/lookup3.c +976 -0
- data/core/vendor/src/crfsuite/lib/crf/Makefile.am +46 -0
- data/core/vendor/src/crfsuite/lib/crf/Makefile.in +721 -0
- data/core/vendor/src/crfsuite/lib/crf/crf.vcxproj +216 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d.h +353 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_context.c +705 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_encode.c +943 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_feature.c +352 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_model.c +994 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_tag.c +550 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crfsuite.c +492 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crfsuite_internal.h +236 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crfsuite_train.c +272 -0
- data/core/vendor/src/crfsuite/lib/crf/src/dataset.c +106 -0
- data/core/vendor/src/crfsuite/lib/crf/src/dictionary.c +118 -0
- data/core/vendor/src/crfsuite/lib/crf/src/holdout.c +80 -0
- data/core/vendor/src/crfsuite/lib/crf/src/logging.c +91 -0
- data/core/vendor/src/crfsuite/lib/crf/src/logging.h +48 -0
- data/core/vendor/src/crfsuite/lib/crf/src/params.c +335 -0
- data/core/vendor/src/crfsuite/lib/crf/src/params.h +80 -0
- data/core/vendor/src/crfsuite/lib/crf/src/quark.c +172 -0
- data/core/vendor/src/crfsuite/lib/crf/src/quark.h +46 -0
- data/core/vendor/src/crfsuite/lib/crf/src/rumavl.c +1107 -0
- data/core/vendor/src/crfsuite/lib/crf/src/rumavl.h +160 -0
- data/core/vendor/src/crfsuite/lib/crf/src/train_arow.c +408 -0
- data/core/vendor/src/crfsuite/lib/crf/src/train_averaged_perceptron.c +242 -0
- data/core/vendor/src/crfsuite/lib/crf/src/train_l2sgd.c +507 -0
- data/core/vendor/src/crfsuite/lib/crf/src/train_lbfgs.c +338 -0
- data/core/vendor/src/crfsuite/lib/crf/src/train_passive_aggressive.c +435 -0
- data/core/vendor/src/crfsuite/lib/crf/src/vecmath.h +341 -0
- data/core/vendor/src/crfsuite/ltmain.sh +8413 -0
- data/core/vendor/src/crfsuite/missing +376 -0
- data/core/vendor/src/crfsuite/swig/Makefile.am +13 -0
- data/core/vendor/src/crfsuite/swig/Makefile.in +365 -0
- data/core/vendor/src/crfsuite/swig/crfsuite.cpp +2 -0
- data/core/vendor/src/crfsuite/swig/export.i +32 -0
- data/core/vendor/src/crfsuite/swig/python/README +92 -0
- data/core/vendor/src/crfsuite/swig/python/crfsuite.py +329 -0
- data/core/vendor/src/crfsuite/swig/python/export_wrap.cpp +14355 -0
- data/core/vendor/src/crfsuite/swig/python/export_wrap.h +63 -0
- data/core/vendor/src/crfsuite/swig/python/prepare.sh +9 -0
- data/core/vendor/src/crfsuite/swig/python/sample_tag.py +52 -0
- data/core/vendor/src/crfsuite/swig/python/sample_train.py +68 -0
- data/core/vendor/src/crfsuite/swig/python/setup.py +44 -0
- data/core/vendor/src/crfsuite/win32/stdint.h +679 -0
- data/core/vendor/src/liblbfgs/AUTHORS +1 -0
- data/core/vendor/src/liblbfgs/COPYING +22 -0
- data/core/vendor/src/liblbfgs/ChangeLog +120 -0
- data/core/vendor/src/liblbfgs/INSTALL +231 -0
- data/core/vendor/src/liblbfgs/Makefile.am +10 -0
- data/core/vendor/src/liblbfgs/Makefile.in +638 -0
- data/core/vendor/src/liblbfgs/NEWS +0 -0
- data/core/vendor/src/liblbfgs/README +71 -0
- data/core/vendor/src/liblbfgs/aclocal.m4 +6985 -0
- data/core/vendor/src/liblbfgs/autogen.sh +38 -0
- data/core/vendor/src/liblbfgs/config.guess +1411 -0
- data/core/vendor/src/liblbfgs/config.h.in +64 -0
- data/core/vendor/src/liblbfgs/config.sub +1500 -0
- data/core/vendor/src/liblbfgs/configure +21146 -0
- data/core/vendor/src/liblbfgs/configure.in +107 -0
- data/core/vendor/src/liblbfgs/depcomp +522 -0
- data/core/vendor/src/liblbfgs/include/lbfgs.h +745 -0
- data/core/vendor/src/liblbfgs/install-sh +322 -0
- data/core/vendor/src/liblbfgs/lbfgs.sln +26 -0
- data/core/vendor/src/liblbfgs/lib/Makefile.am +24 -0
- data/core/vendor/src/liblbfgs/lib/Makefile.in +499 -0
- data/core/vendor/src/liblbfgs/lib/arithmetic_ansi.h +133 -0
- data/core/vendor/src/liblbfgs/lib/arithmetic_sse_double.h +294 -0
- data/core/vendor/src/liblbfgs/lib/arithmetic_sse_float.h +298 -0
- data/core/vendor/src/liblbfgs/lib/lbfgs.c +1371 -0
- data/core/vendor/src/liblbfgs/lib/lib.vcxproj +95 -0
- data/core/vendor/src/liblbfgs/ltmain.sh +6426 -0
- data/core/vendor/src/liblbfgs/missing +353 -0
- data/core/vendor/src/liblbfgs/sample/Makefile.am +15 -0
- data/core/vendor/src/liblbfgs/sample/Makefile.in +433 -0
- data/core/vendor/src/liblbfgs/sample/sample.c +81 -0
- data/core/vendor/src/liblbfgs/sample/sample.cpp +126 -0
- data/core/vendor/src/liblbfgs/sample/sample.vcxproj +105 -0
- data/core/vendor/src/svm_light/LICENSE.txt +59 -0
- data/core/vendor/src/svm_light/Makefile +105 -0
- data/core/vendor/src/svm_light/kernel.h +40 -0
- data/core/vendor/src/svm_light/svm_classify.c +197 -0
- data/core/vendor/src/svm_light/svm_common.c +985 -0
- data/core/vendor/src/svm_light/svm_common.h +301 -0
- data/core/vendor/src/svm_light/svm_hideo.c +1062 -0
- data/core/vendor/src/svm_light/svm_learn.c +4147 -0
- data/core/vendor/src/svm_light/svm_learn.h +169 -0
- data/core/vendor/src/svm_light/svm_learn_main.c +397 -0
- data/core/vendor/src/svm_light/svm_loqo.c +211 -0
- data/ext/hack/Rakefile +17 -0
- data/ext/hack/support.rb +88 -0
- data/lib/opener/opinion_detectors/base.rb +112 -0
- data/lib/opener/opinion_detectors/base/version.rb +7 -0
- data/lib/opener/opinion_detectors/configuration_creator.rb +86 -0
- data/lib/opener/opinion_detectors/de.rb +7 -0
- data/lib/opener/opinion_detectors/en.rb +7 -0
- data/lib/opener/opinion_detectors/it.rb +7 -0
- data/lib/opener/opinion_detectors/nl.rb +6 -0
- data/opener-opinion-detector-base.gemspec +35 -0
- data/pre_build_requirements.txt +3 -0
- metadata +374 -0
Binary file
|
@@ -0,0 +1,211 @@
|
|
1
|
+
#Modified for KAF NAF ok
|
2
|
+
|
3
|
+
from lxml import etree
|
4
|
+
from lxml.objectify import dump
|
5
|
+
from span_data import *
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
class Cholder:
|
10
|
+
def __init__(self,node=None):
|
11
|
+
self.type = 'NAF/KAF'
|
12
|
+
if node is None:
|
13
|
+
self.node = etree.Element('opinion_holder')
|
14
|
+
else:
|
15
|
+
self.node = node
|
16
|
+
|
17
|
+
def set_span(self,my_span):
|
18
|
+
self.node.append(my_span.get_node())
|
19
|
+
|
20
|
+
def set_comment(self,c):
|
21
|
+
c = c.replace('--','- -')
|
22
|
+
self.node.insert(0,etree.Comment(c) )
|
23
|
+
|
24
|
+
def get_span(self):
|
25
|
+
span_obj = self.node.find('span')
|
26
|
+
if span_obj is not None:
|
27
|
+
return Cspan(span_obj)
|
28
|
+
return None
|
29
|
+
|
30
|
+
def __str__(self):
|
31
|
+
return dump(self.node)
|
32
|
+
|
33
|
+
def get_node(self):
|
34
|
+
return self.node
|
35
|
+
|
36
|
+
|
37
|
+
class Ctarget:
|
38
|
+
def __init__(self,node=None):
|
39
|
+
self.type = 'NAF/KAF'
|
40
|
+
if node is None:
|
41
|
+
self.node = etree.Element('opinion_target')
|
42
|
+
else:
|
43
|
+
self.node = node
|
44
|
+
|
45
|
+
def set_comment(self,c):
|
46
|
+
c = c.replace('--','- -')
|
47
|
+
self.node.insert(0,etree.Comment(c) )
|
48
|
+
|
49
|
+
def get_comment(self):
|
50
|
+
return self.node_comment
|
51
|
+
|
52
|
+
def set_span(self,my_span):
|
53
|
+
self.node.append(my_span.get_node())
|
54
|
+
|
55
|
+
def get_span(self):
|
56
|
+
span_obj = self.node.find('span')
|
57
|
+
if span_obj is not None:
|
58
|
+
return Cspan(span_obj)
|
59
|
+
return None
|
60
|
+
|
61
|
+
def __str__(self):
|
62
|
+
return dump(self.node)
|
63
|
+
|
64
|
+
def get_node(self):
|
65
|
+
return self.node
|
66
|
+
|
67
|
+
|
68
|
+
class Cexpression:
|
69
|
+
def __init__(self,node=None):
|
70
|
+
self.type = 'NAF/KAF'
|
71
|
+
if node is None:
|
72
|
+
self.node = etree.Element('opinion_expression')
|
73
|
+
else:
|
74
|
+
self.node = node
|
75
|
+
|
76
|
+
def set_comment(self,c):
|
77
|
+
c = c.replace('--','- -')
|
78
|
+
self.node.insert(0,etree.Comment(c))
|
79
|
+
|
80
|
+
def set_polarity(self,pol):
|
81
|
+
self.node.set('polarity',pol)
|
82
|
+
|
83
|
+
def get_polarity(self):
|
84
|
+
return self.node.get('polarity')
|
85
|
+
|
86
|
+
def set_strength(self,st):
|
87
|
+
self.node.set('strength',st)
|
88
|
+
|
89
|
+
def get_strength(self):
|
90
|
+
return self.node.get('strength')
|
91
|
+
|
92
|
+
def set_span(self,my_span):
|
93
|
+
self.node.append(my_span.get_node())
|
94
|
+
|
95
|
+
def get_span(self):
|
96
|
+
span_obj = self.node.find('span')
|
97
|
+
if span_obj is not None:
|
98
|
+
return Cspan(span_obj)
|
99
|
+
return None
|
100
|
+
|
101
|
+
def __str__(self):
|
102
|
+
return dump(self.node)
|
103
|
+
|
104
|
+
def get_node(self):
|
105
|
+
return self.node
|
106
|
+
|
107
|
+
class Copinion:
|
108
|
+
def __init__(self,node=None,type='NAF'):
|
109
|
+
self.type = type
|
110
|
+
if node is None:
|
111
|
+
self.node = etree.Element('opinion')
|
112
|
+
else:
|
113
|
+
self.node = node
|
114
|
+
|
115
|
+
def set_comment(self,c):
|
116
|
+
c = c.replace('--','- -')
|
117
|
+
self.node.insert(0,etree.Comment(c) )
|
118
|
+
|
119
|
+
def set_id(self,my_id):
|
120
|
+
if self.type == 'NAF':
|
121
|
+
self.node.set('id',my_id)
|
122
|
+
elif self.type == 'KAF':
|
123
|
+
self.node.set('oid',my_id)
|
124
|
+
|
125
|
+
def get_id(self):
|
126
|
+
if self.type == 'NAF':
|
127
|
+
return self.node.get('id')
|
128
|
+
elif self.type == 'KAF':
|
129
|
+
return self.node.get('oid')
|
130
|
+
|
131
|
+
def set_holder(self,hol):
|
132
|
+
self.node.append(hol.get_node())
|
133
|
+
|
134
|
+
def get_holder(self):
|
135
|
+
node_hol = self.node.find('opinion_holder')
|
136
|
+
if node_hol is not None:
|
137
|
+
return Cholder(node_hol)
|
138
|
+
else:
|
139
|
+
return None
|
140
|
+
|
141
|
+
def set_target(self,tar):
|
142
|
+
self.node.append(tar.get_node())
|
143
|
+
|
144
|
+
def get_target(self):
|
145
|
+
node_target = self.node.find('opinion_target')
|
146
|
+
if node_target is not None:
|
147
|
+
return Ctarget(node_target)
|
148
|
+
else:
|
149
|
+
return None
|
150
|
+
|
151
|
+
def set_expression(self,exp):
|
152
|
+
self.node.append(exp.get_node())
|
153
|
+
|
154
|
+
def get_expression(self):
|
155
|
+
node_exp = self.node.find('opinion_expression')
|
156
|
+
if node_exp is not None:
|
157
|
+
return Cexpression(node_exp)
|
158
|
+
else:
|
159
|
+
return None
|
160
|
+
|
161
|
+
def __str__(self):
|
162
|
+
return dump(self.node)
|
163
|
+
|
164
|
+
def get_node(self):
|
165
|
+
return self.node
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
class Copinions:
|
172
|
+
def __init__(self,node=None,type='NAF'):
|
173
|
+
self.type = type
|
174
|
+
if node is None:
|
175
|
+
self.node = etree.Element('opinions')
|
176
|
+
else:
|
177
|
+
self.node = node
|
178
|
+
|
179
|
+
def __get_opinion_nodes(self):
|
180
|
+
for node in self.node.findall('opinion'):
|
181
|
+
yield node
|
182
|
+
|
183
|
+
def get_opinions(self):
|
184
|
+
for node in self.__get_opinion_nodes():
|
185
|
+
yield Copinion(node,self.type)
|
186
|
+
|
187
|
+
def to_kaf(self):
|
188
|
+
if self.type == 'NAF':
|
189
|
+
for node in self.__get_opinion_nodes():
|
190
|
+
node.set('oid',node.get('id'))
|
191
|
+
del node.attrib['id']
|
192
|
+
|
193
|
+
def to_naf(self):
|
194
|
+
if self.type == 'KAF':
|
195
|
+
for node in self.__get_opinion_nodes():
|
196
|
+
node.set('id',node.get('oid'))
|
197
|
+
del node.attrib['oid']
|
198
|
+
|
199
|
+
|
200
|
+
def add_opinion(self,opi_obj):
|
201
|
+
self.node.append(opi_obj.get_node())
|
202
|
+
|
203
|
+
def get_node(self):
|
204
|
+
return self.node
|
205
|
+
|
206
|
+
def remove_this_opinion(self,opinion_id):
|
207
|
+
for opi in self.get_opinions():
|
208
|
+
if opi.get_id() == opinion_id:
|
209
|
+
self.node.remove(opi.get_node())
|
210
|
+
break
|
211
|
+
|
Binary file
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Modified for NAF/KAf
|
2
|
+
from span_data import *
|
3
|
+
|
4
|
+
class Creferences:
|
5
|
+
def __init__(self,node=None):
|
6
|
+
self.type = 'NAF/KAF'
|
7
|
+
if node is None:
|
8
|
+
self.node = etree.Element('references')
|
9
|
+
else:
|
10
|
+
self.node = node
|
11
|
+
|
12
|
+
def get_node(self):
|
13
|
+
return self.node
|
14
|
+
|
15
|
+
def __iter__(self):
|
16
|
+
for span_node in self.node.findall('span'):
|
17
|
+
yield Cspan(span_node)
|
18
|
+
|
19
|
+
def add_span(self,term_span):
|
20
|
+
new_span = Cspan()
|
21
|
+
new_span.create_from_ids(term_span)
|
22
|
+
self.node.append(new_span.get_node())
|
23
|
+
|
Binary file
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# Modified for KAF/NAF
|
2
|
+
|
3
|
+
from lxml import etree
|
4
|
+
from lxml.objectify import dump
|
5
|
+
|
6
|
+
class Ctarget:
|
7
|
+
def __init__(self,node=None):
|
8
|
+
self.type = 'NAF/KAF'
|
9
|
+
if node is None:
|
10
|
+
self.node = etree.Element('target')
|
11
|
+
else:
|
12
|
+
self.node = node
|
13
|
+
|
14
|
+
def get_id(self):
|
15
|
+
return self.node.get('id')
|
16
|
+
|
17
|
+
def set_id(self,this_id):
|
18
|
+
self.node.set('id',this_id)
|
19
|
+
|
20
|
+
def get_node(self):
|
21
|
+
return self.node
|
22
|
+
|
23
|
+
|
24
|
+
class Cspan:
|
25
|
+
def __init__(self,node=None):
|
26
|
+
self.type = 'NAF/KAF'
|
27
|
+
if node is None:
|
28
|
+
self.node = etree.Element('span')
|
29
|
+
else:
|
30
|
+
self.node = node
|
31
|
+
|
32
|
+
def add_target_id(self,this_id):
|
33
|
+
new_target = Ctarget()
|
34
|
+
new_target.set_id(this_id)
|
35
|
+
self.node.append(new_target.get_node())
|
36
|
+
|
37
|
+
def create_from_ids(self,list_ids):
|
38
|
+
for this_id in list_ids:
|
39
|
+
new_target = Ctarget()
|
40
|
+
new_target.set_id(this_id)
|
41
|
+
self.node.append(new_target.get_node())
|
42
|
+
|
43
|
+
def add_target(self,target):
|
44
|
+
self.node.append(target.get_node())
|
45
|
+
|
46
|
+
|
47
|
+
def __get_target_nodes(self):
|
48
|
+
for target_node in self.node.findall('target'):
|
49
|
+
yield target_node
|
50
|
+
|
51
|
+
def __iter__(self):
|
52
|
+
for target_node in self.__get_target_nodes():
|
53
|
+
yield Ctarget(target_node)
|
54
|
+
|
55
|
+
def get_span_ids(self):
|
56
|
+
return [t_obj.get_id() for t_obj in self]
|
57
|
+
|
58
|
+
def __str__(self):
|
59
|
+
return dump(self.node)
|
60
|
+
|
61
|
+
def get_node(self):
|
62
|
+
return self.node
|
63
|
+
|
Binary file
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# included code for NAF/KAF
|
2
|
+
|
3
|
+
|
4
|
+
from span_data import *
|
5
|
+
from external_references_data import *
|
6
|
+
from term_sentiment_data import *
|
7
|
+
from lxml import etree
|
8
|
+
|
9
|
+
|
10
|
+
class Cterm:
|
11
|
+
def __init__(self,node=None,type='NAF'):
|
12
|
+
self.type = type
|
13
|
+
if node is None:
|
14
|
+
self.node = etree.Element('term')
|
15
|
+
else:
|
16
|
+
self.node = node
|
17
|
+
|
18
|
+
|
19
|
+
def get_id(self):
|
20
|
+
if self.type == 'NAF':
|
21
|
+
return self.node.get('id')
|
22
|
+
elif self.type == 'KAF':
|
23
|
+
return self.node.get('tid')
|
24
|
+
|
25
|
+
def get_lemma(self):
|
26
|
+
return self.node.get('lemma')
|
27
|
+
|
28
|
+
def get_pos(self):
|
29
|
+
return self.node.get('pos')
|
30
|
+
|
31
|
+
def get_morphofeat(self):
|
32
|
+
return self.node.get('morphofeat')
|
33
|
+
|
34
|
+
def get_span(self):
|
35
|
+
node_span = self.node.find('span')
|
36
|
+
if node_span is not None:
|
37
|
+
return Cspan(node_span)
|
38
|
+
else:
|
39
|
+
return None
|
40
|
+
|
41
|
+
def get_sentiment(self):
|
42
|
+
sent_node = self.node.find('sentiment')
|
43
|
+
|
44
|
+
if sent_node is None:
|
45
|
+
return None
|
46
|
+
else:
|
47
|
+
return Cterm_sentiment(sent_node)
|
48
|
+
|
49
|
+
|
50
|
+
def add_external_reference(self,ext_ref):
|
51
|
+
ext_refs_node = self.node.find('externalReferences')
|
52
|
+
if ext_refs_node is None:
|
53
|
+
ext_refs_obj = CexternalReferences()
|
54
|
+
self.node.append(ext_refs_obj.get_node())
|
55
|
+
else:
|
56
|
+
ext_refs_obj = CexternalReferences(ext_refs_node)
|
57
|
+
|
58
|
+
ext_refs_obj.add_external_reference(ext_ref)
|
59
|
+
|
60
|
+
def add_term_sentiment(self,term_sentiment):
|
61
|
+
self.node.append(term_sentiment.get_node())
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
class Cterms:
|
67
|
+
def __init__(self,node=None,type='NAF'):
|
68
|
+
self.idx = {}
|
69
|
+
self.type = type
|
70
|
+
if node is None:
|
71
|
+
self.node = etree.Element('terms')
|
72
|
+
else:
|
73
|
+
self.node = node
|
74
|
+
for node_term in self.__get_node_terms():
|
75
|
+
self.idx[node_term.get('id')] = node_term
|
76
|
+
|
77
|
+
def get_node(self):
|
78
|
+
return self.node
|
79
|
+
|
80
|
+
def to_kaf(self):
|
81
|
+
if self.type == 'NAF':
|
82
|
+
self.type = 'KAF'
|
83
|
+
for node in self.__get_node_terms():
|
84
|
+
node.set('tid',node.get('id'))
|
85
|
+
del node.attrib['id']
|
86
|
+
|
87
|
+
def to_naf(self):
|
88
|
+
if self.type == 'KAF':
|
89
|
+
self.type = 'NAF'
|
90
|
+
for node in self.__get_node_terms():
|
91
|
+
node.set('id',node.get('tid'))
|
92
|
+
del node.attrib['tid']
|
93
|
+
|
94
|
+
def __get_node_terms(self):
|
95
|
+
for node_term in self.node.findall('term'):
|
96
|
+
yield node_term
|
97
|
+
|
98
|
+
def __iter__(self):
|
99
|
+
for node_term in self.__get_node_terms():
|
100
|
+
yield Cterm(node_term,self.type)
|
101
|
+
|
102
|
+
def get_term(self,term_id):
|
103
|
+
if term_id in self.idx:
|
104
|
+
return Cterm(self.idx[term_id],self.type)
|
105
|
+
else:
|
106
|
+
return None
|
107
|
+
|
108
|
+
def add_external_reference(self,term_id, external_ref):
|
109
|
+
if term_id in self.idx:
|
110
|
+
term_obj = Cterm(self.idx[term_id],self.type)
|
111
|
+
term_obj.add_external_reference(external_ref)
|
Binary file
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Modified for NAF KAF
|
2
|
+
from lxml import etree
|
3
|
+
from lxml.objectify import dump
|
4
|
+
|
5
|
+
class Cterm_sentiment:
|
6
|
+
def __init__(self,node=None):
|
7
|
+
self.type = 'NAF/KAF'
|
8
|
+
if node is None:
|
9
|
+
self.node = etree.Element('sentiment')
|
10
|
+
else:
|
11
|
+
self.node = node
|
12
|
+
#self.resource = self.polarity = self.strength = self.subjectivity = self.semantic_type = self.modifier = self.marker = self.product_feature = ''
|
13
|
+
#if node is not None:
|
14
|
+
# self.resource = node.get('resource','')
|
15
|
+
# self.polarity = node.get('polarity','')
|
16
|
+
# self.strength = node.get('strength','')
|
17
|
+
# self.subjectivity = node.get('subjectivity','')
|
18
|
+
#self.semantic_type = node.get('sentiment_semantic_type','')
|
19
|
+
# self.modifier = node.get('sentiment modifier','')
|
20
|
+
# self.marker = node.get('sentiment_marker','')
|
21
|
+
# self.product_feature = node.get('sentiment product feature','')
|
22
|
+
|
23
|
+
def set_resource(self,r):
|
24
|
+
self.node.set('resource',r)
|
25
|
+
|
26
|
+
def get_node(self):
|
27
|
+
return self.node
|
28
|
+
|
29
|
+
def get_polarity(self):
|
30
|
+
return self.node.get('polarity')
|
31
|
+
|
32
|
+
def set_polarity(self,p):
|
33
|
+
self.node.set('polarity',p)
|
34
|
+
|
35
|
+
def get_modifier(self):
|
36
|
+
return self.node.get('sentiment_modifier')
|
37
|
+
|
38
|
+
def set_modifier(self,sm):
|
39
|
+
self.node.set('sentiment_modifier',sm)
|
40
|
+
|
41
|
+
def __str__(self):
|
42
|
+
return dump(self.node)
|