arekit 0.24.0__py3-none-any.whl → 0.25.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- arekit/common/data/storages/base.py +4 -15
- arekit/common/docs/entities_grouping.py +2 -1
- arekit/common/docs/parser.py +27 -22
- arekit/common/pipeline/base.py +12 -16
- arekit/common/pipeline/batching.py +28 -0
- arekit/common/pipeline/context.py +5 -1
- arekit/common/pipeline/items/base.py +39 -2
- arekit/common/pipeline/items/flatten.py +5 -1
- arekit/common/pipeline/items/handle.py +2 -1
- arekit/common/pipeline/items/iter.py +2 -1
- arekit/common/pipeline/items/map.py +2 -1
- arekit/common/pipeline/items/map_nested.py +4 -0
- arekit/common/pipeline/utils.py +32 -0
- arekit/common/text/{partitioning/str.py → partitioning.py} +14 -9
- arekit/common/utils.py +11 -52
- arekit/contrib/utils/data/contents/opinions.py +13 -3
- arekit/contrib/utils/data/storages/jsonl_based.py +2 -1
- arekit/contrib/utils/data/storages/pandas_based.py +2 -17
- arekit/contrib/utils/data/storages/row_cache.py +8 -2
- arekit/contrib/utils/data/storages/sqlite_based.py +18 -0
- arekit/contrib/utils/io_utils/utils.py +1 -18
- arekit/contrib/utils/pipelines/items/text/entities_default.py +2 -2
- arekit/contrib/utils/pipelines/items/text/frames.py +2 -3
- arekit/contrib/utils/pipelines/text_opinion/extraction.py +8 -10
- arekit-0.25.1.data/data/logo.png +0 -0
- arekit-0.25.1.dist-info/METADATA +81 -0
- arekit-0.25.1.dist-info/RECORD +186 -0
- {arekit-0.24.0.dist-info → arekit-0.25.1.dist-info}/WHEEL +1 -1
- arekit/common/data/input/repositories/__init__.py +0 -0
- arekit/common/data/input/repositories/base.py +0 -68
- arekit/common/data/input/repositories/sample.py +0 -22
- arekit/common/data/views/__init__.py +0 -0
- arekit/common/data/views/samples.py +0 -26
- arekit/common/docs/objects_parser.py +0 -37
- arekit/common/text/parser.py +0 -12
- arekit/common/text/partitioning/__init__.py +0 -0
- arekit/common/text/partitioning/base.py +0 -4
- arekit/common/text/partitioning/terms.py +0 -35
- arekit/contrib/networks/__init__.py +0 -0
- arekit/contrib/networks/embedding.py +0 -149
- arekit/contrib/networks/embedding_io.py +0 -18
- arekit/contrib/networks/input/__init__.py +0 -0
- arekit/contrib/networks/input/const.py +0 -6
- arekit/contrib/networks/input/ctx_serialization.py +0 -28
- arekit/contrib/networks/input/embedding/__init__.py +0 -0
- arekit/contrib/networks/input/embedding/matrix.py +0 -29
- arekit/contrib/networks/input/embedding/offsets.py +0 -55
- arekit/contrib/networks/input/formatters/__init__.py +0 -0
- arekit/contrib/networks/input/formatters/pos_mapper.py +0 -22
- arekit/contrib/networks/input/providers/__init__.py +0 -0
- arekit/contrib/networks/input/providers/sample.py +0 -129
- arekit/contrib/networks/input/providers/term_connotation.py +0 -23
- arekit/contrib/networks/input/providers/text.py +0 -24
- arekit/contrib/networks/input/rows_parser.py +0 -47
- arekit/contrib/networks/input/term_types.py +0 -13
- arekit/contrib/networks/input/terms_mapping.py +0 -60
- arekit/contrib/networks/vectorizer.py +0 -6
- arekit/contrib/source/__init__.py +0 -0
- arekit/contrib/source/brat/__init__.py +0 -0
- arekit/contrib/source/brat/annot.py +0 -84
- arekit/contrib/source/brat/doc.py +0 -28
- arekit/contrib/source/brat/entities/__init__.py +0 -0
- arekit/contrib/source/brat/entities/compound.py +0 -13
- arekit/contrib/source/brat/entities/entity.py +0 -42
- arekit/contrib/source/brat/entities/parser.py +0 -53
- arekit/contrib/source/brat/opinions/__init__.py +0 -0
- arekit/contrib/source/brat/opinions/converter.py +0 -19
- arekit/contrib/source/brat/relation.py +0 -32
- arekit/contrib/source/brat/sentence.py +0 -69
- arekit/contrib/source/brat/sentences_reader.py +0 -128
- arekit/contrib/source/download.py +0 -41
- arekit/contrib/source/nerel/__init__.py +0 -0
- arekit/contrib/source/nerel/entities.py +0 -55
- arekit/contrib/source/nerel/folding/__init__.py +0 -0
- arekit/contrib/source/nerel/folding/fixed.py +0 -74
- arekit/contrib/source/nerel/io_utils.py +0 -62
- arekit/contrib/source/nerel/labels.py +0 -241
- arekit/contrib/source/nerel/reader.py +0 -46
- arekit/contrib/source/nerel/utils.py +0 -24
- arekit/contrib/source/nerel/versions.py +0 -12
- arekit/contrib/source/nerelbio/__init__.py +0 -0
- arekit/contrib/source/nerelbio/io_utils.py +0 -62
- arekit/contrib/source/nerelbio/labels.py +0 -265
- arekit/contrib/source/nerelbio/reader.py +0 -8
- arekit/contrib/source/nerelbio/versions.py +0 -8
- arekit/contrib/source/ruattitudes/__init__.py +0 -0
- arekit/contrib/source/ruattitudes/collection.py +0 -36
- arekit/contrib/source/ruattitudes/doc.py +0 -51
- arekit/contrib/source/ruattitudes/doc_brat.py +0 -44
- arekit/contrib/source/ruattitudes/entity/__init__.py +0 -0
- arekit/contrib/source/ruattitudes/entity/parser.py +0 -7
- arekit/contrib/source/ruattitudes/io_utils.py +0 -56
- arekit/contrib/source/ruattitudes/labels_fmt.py +0 -12
- arekit/contrib/source/ruattitudes/opinions/__init__.py +0 -0
- arekit/contrib/source/ruattitudes/opinions/base.py +0 -28
- arekit/contrib/source/ruattitudes/opinions/converter.py +0 -37
- arekit/contrib/source/ruattitudes/reader.py +0 -268
- arekit/contrib/source/ruattitudes/sentence.py +0 -73
- arekit/contrib/source/ruattitudes/synonyms.py +0 -17
- arekit/contrib/source/ruattitudes/text_object.py +0 -59
- arekit/contrib/source/rusentiframes/__init__.py +0 -0
- arekit/contrib/source/rusentiframes/collection.py +0 -157
- arekit/contrib/source/rusentiframes/effect.py +0 -24
- arekit/contrib/source/rusentiframes/io_utils.py +0 -19
- arekit/contrib/source/rusentiframes/labels_fmt.py +0 -22
- arekit/contrib/source/rusentiframes/polarity.py +0 -35
- arekit/contrib/source/rusentiframes/role.py +0 -15
- arekit/contrib/source/rusentiframes/state.py +0 -24
- arekit/contrib/source/rusentiframes/types.py +0 -42
- arekit/contrib/source/rusentiframes/value.py +0 -2
- arekit/contrib/source/rusentrel/__init__.py +0 -0
- arekit/contrib/source/rusentrel/const.py +0 -3
- arekit/contrib/source/rusentrel/docs_reader.py +0 -51
- arekit/contrib/source/rusentrel/entities.py +0 -26
- arekit/contrib/source/rusentrel/io_utils.py +0 -125
- arekit/contrib/source/rusentrel/labels_fmt.py +0 -12
- arekit/contrib/source/rusentrel/opinions/__init__.py +0 -0
- arekit/contrib/source/rusentrel/opinions/collection.py +0 -30
- arekit/contrib/source/rusentrel/opinions/converter.py +0 -40
- arekit/contrib/source/rusentrel/opinions/provider.py +0 -54
- arekit/contrib/source/rusentrel/opinions/writer.py +0 -42
- arekit/contrib/source/rusentrel/synonyms.py +0 -17
- arekit/contrib/source/sentinerel/__init__.py +0 -0
- arekit/contrib/source/sentinerel/entities.py +0 -52
- arekit/contrib/source/sentinerel/folding/__init__.py +0 -0
- arekit/contrib/source/sentinerel/folding/factory.py +0 -31
- arekit/contrib/source/sentinerel/folding/fixed.py +0 -70
- arekit/contrib/source/sentinerel/io_utils.py +0 -87
- arekit/contrib/source/sentinerel/labels.py +0 -53
- arekit/contrib/source/sentinerel/labels_scaler.py +0 -30
- arekit/contrib/source/sentinerel/reader.py +0 -42
- arekit/contrib/source/synonyms/__init__.py +0 -0
- arekit/contrib/source/synonyms/utils.py +0 -19
- arekit/contrib/source/zip_utils.py +0 -47
- arekit/contrib/utils/connotations/__init__.py +0 -0
- arekit/contrib/utils/connotations/rusentiframes_sentiment.py +0 -23
- arekit/contrib/utils/data/readers/__init__.py +0 -0
- arekit/contrib/utils/data/readers/base.py +0 -7
- arekit/contrib/utils/data/readers/csv_pd.py +0 -38
- arekit/contrib/utils/data/readers/jsonl.py +0 -15
- arekit/contrib/utils/data/service/__init__.py +0 -0
- arekit/contrib/utils/data/service/balance.py +0 -50
- arekit/contrib/utils/data/writers/csv_native.py +0 -63
- arekit/contrib/utils/data/writers/csv_pd.py +0 -40
- arekit/contrib/utils/data/writers/json_opennre.py +0 -132
- arekit/contrib/utils/data/writers/sqlite_native.py +0 -110
- arekit/contrib/utils/download.py +0 -77
- arekit/contrib/utils/embeddings/__init__.py +0 -0
- arekit/contrib/utils/embeddings/rusvectores.py +0 -58
- arekit/contrib/utils/embeddings/tokens.py +0 -30
- arekit/contrib/utils/io_utils/embedding.py +0 -72
- arekit/contrib/utils/io_utils/opinions.py +0 -37
- arekit/contrib/utils/io_utils/samples.py +0 -79
- arekit/contrib/utils/lexicons/__init__.py +0 -0
- arekit/contrib/utils/lexicons/lexicon.py +0 -41
- arekit/contrib/utils/lexicons/relation.py +0 -42
- arekit/contrib/utils/lexicons/rusentilex.py +0 -37
- arekit/contrib/utils/nn/__init__.py +0 -0
- arekit/contrib/utils/nn/rows.py +0 -83
- arekit/contrib/utils/np_utils/__init__.py +0 -0
- arekit/contrib/utils/np_utils/embedding.py +0 -22
- arekit/contrib/utils/np_utils/npz_utils.py +0 -13
- arekit/contrib/utils/np_utils/vocab.py +0 -20
- arekit/contrib/utils/pipelines/items/sampling/__init__.py +0 -0
- arekit/contrib/utils/pipelines/items/sampling/base.py +0 -99
- arekit/contrib/utils/pipelines/items/sampling/networks.py +0 -54
- arekit/contrib/utils/pipelines/items/text/frames_lemmatized.py +0 -36
- arekit/contrib/utils/pipelines/items/text/frames_negation.py +0 -32
- arekit/contrib/utils/pipelines/items/text/terms_splitter.py +0 -10
- arekit/contrib/utils/pipelines/items/text/tokenizer.py +0 -107
- arekit/contrib/utils/pipelines/items/text/translator.py +0 -135
- arekit/contrib/utils/pipelines/sources/__init__.py +0 -0
- arekit/contrib/utils/pipelines/sources/nerel/__init__.py +0 -0
- arekit/contrib/utils/pipelines/sources/nerel/doc_provider.py +0 -27
- arekit/contrib/utils/pipelines/sources/nerel/extract_text_relations.py +0 -65
- arekit/contrib/utils/pipelines/sources/nerel/labels_fmt.py +0 -60
- arekit/contrib/utils/pipelines/sources/nerel_bio/__init__.py +0 -0
- arekit/contrib/utils/pipelines/sources/nerel_bio/doc_provider.py +0 -29
- arekit/contrib/utils/pipelines/sources/nerel_bio/extrat_text_relations.py +0 -64
- arekit/contrib/utils/pipelines/sources/nerel_bio/labels_fmt.py +0 -79
- arekit/contrib/utils/pipelines/sources/ruattitudes/__init__.py +0 -0
- arekit/contrib/utils/pipelines/sources/ruattitudes/doc_provider.py +0 -56
- arekit/contrib/utils/pipelines/sources/ruattitudes/entity_filter.py +0 -20
- arekit/contrib/utils/pipelines/sources/ruattitudes/extract_text_opinions.py +0 -65
- arekit/contrib/utils/pipelines/sources/rusentrel/__init__.py +0 -0
- arekit/contrib/utils/pipelines/sources/rusentrel/doc_provider.py +0 -21
- arekit/contrib/utils/pipelines/sources/rusentrel/extract_text_opinions.py +0 -107
- arekit/contrib/utils/pipelines/sources/sentinerel/__init__.py +0 -0
- arekit/contrib/utils/pipelines/sources/sentinerel/doc_provider.py +0 -29
- arekit/contrib/utils/pipelines/sources/sentinerel/entity_filter.py +0 -62
- arekit/contrib/utils/pipelines/sources/sentinerel/extract_text_opinions.py +0 -180
- arekit/contrib/utils/pipelines/sources/sentinerel/labels_fmt.py +0 -50
- arekit/contrib/utils/pipelines/text_opinion/annot/predefined.py +0 -88
- arekit/contrib/utils/processing/languages/__init__.py +0 -0
- arekit/contrib/utils/processing/languages/mods.py +0 -12
- arekit/contrib/utils/processing/languages/pos.py +0 -23
- arekit/contrib/utils/processing/languages/ru/__init__.py +0 -0
- arekit/contrib/utils/processing/languages/ru/cases.py +0 -78
- arekit/contrib/utils/processing/languages/ru/constants.py +0 -6
- arekit/contrib/utils/processing/languages/ru/mods.py +0 -13
- arekit/contrib/utils/processing/languages/ru/number.py +0 -23
- arekit/contrib/utils/processing/languages/ru/pos_service.py +0 -36
- arekit/contrib/utils/processing/lemmatization/__init__.py +0 -0
- arekit/contrib/utils/processing/lemmatization/mystem.py +0 -51
- arekit/contrib/utils/processing/pos/__init__.py +0 -0
- arekit/contrib/utils/processing/pos/base.py +0 -12
- arekit/contrib/utils/processing/pos/mystem_wrap.py +0 -134
- arekit/contrib/utils/processing/pos/russian.py +0 -10
- arekit/contrib/utils/processing/text/__init__.py +0 -0
- arekit/contrib/utils/processing/text/tokens.py +0 -127
- arekit/contrib/utils/resources.py +0 -25
- arekit/contrib/utils/serializer.py +0 -43
- arekit/contrib/utils/sources/__init__.py +0 -0
- arekit/contrib/utils/sources/sentinerel/__init__.py +0 -0
- arekit/contrib/utils/sources/sentinerel/text_opinion/__init__.py +0 -0
- arekit/contrib/utils/sources/sentinerel/text_opinion/prof_per_org_filter.py +0 -63
- arekit/contrib/utils/vectorizers/__init__.py +0 -0
- arekit/contrib/utils/vectorizers/bpe.py +0 -93
- arekit/contrib/utils/vectorizers/random_norm.py +0 -39
- arekit/download_data.py +0 -11
- arekit-0.24.0.dist-info/METADATA +0 -23
- arekit-0.24.0.dist-info/RECORD +0 -374
- {arekit-0.24.0.dist-info → arekit-0.25.1.dist-info}/LICENSE +0 -0
- {arekit-0.24.0.dist-info → arekit-0.25.1.dist-info}/top_level.txt +0 -0
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
from arekit.common.labels.scaler.base import BaseLabelScaler
|
|
2
|
-
from arekit.contrib.source.ruattitudes.io_utils import RuAttitudesVersions
|
|
3
|
-
from arekit.contrib.source.ruattitudes.labels_fmt import RuAttitudesLabelFormatter
|
|
4
|
-
from arekit.contrib.utils.pipelines.sources.ruattitudes.doc_provider import RuAttitudesDocumentProvider
|
|
5
|
-
from arekit.contrib.utils.pipelines.sources.ruattitudes.entity_filter import RuAttitudesEntityFilter
|
|
6
|
-
from arekit.contrib.utils.pipelines.text_opinion.annot.predefined import PredefinedTextOpinionAnnotator
|
|
7
|
-
from arekit.contrib.utils.pipelines.text_opinion.extraction import text_opinion_extraction_pipeline
|
|
8
|
-
from arekit.contrib.utils.pipelines.text_opinion.filters.distance_based import DistanceLimitedTextOpinionFilter
|
|
9
|
-
from arekit.contrib.utils.pipelines.text_opinion.filters.entity_based import EntityBasedTextOpinionFilter
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def create_text_opinion_extraction_pipeline(text_parser,
|
|
13
|
-
label_scaler,
|
|
14
|
-
custom_text_opinion_filters=None,
|
|
15
|
-
version=RuAttitudesVersions.V20Large,
|
|
16
|
-
terms_per_context=50,
|
|
17
|
-
limit=None):
|
|
18
|
-
""" Processing pipeline for RuAttitudes.
|
|
19
|
-
This pipeline is based on the in-memory RuAttitudes storage.
|
|
20
|
-
|
|
21
|
-
Original collection paper: www.aclweb.org/anthology/r19-1118/
|
|
22
|
-
Github repository: https://github.com/nicolay-r/RuAttitudes
|
|
23
|
-
|
|
24
|
-
version: enum
|
|
25
|
-
Version of the RuAttitudes collection.
|
|
26
|
-
NOTE: we consider to support a variations of the 2.0 versions.
|
|
27
|
-
label_scaler:
|
|
28
|
-
Scaler that allows to perform conversion from integer labels (RuAttitudes) to
|
|
29
|
-
the actual `Label` instances, required in further for text_opinions instances.
|
|
30
|
-
terms_per_context: int
|
|
31
|
-
Amount of terms that we consider in between the Object and Subject.
|
|
32
|
-
limit: int or None
|
|
33
|
-
Limit of documents to consider.
|
|
34
|
-
"""
|
|
35
|
-
assert(isinstance(label_scaler, BaseLabelScaler))
|
|
36
|
-
assert(isinstance(version, RuAttitudesVersions))
|
|
37
|
-
assert(isinstance(custom_text_opinion_filters, list) or custom_text_opinion_filters is None)
|
|
38
|
-
assert(version in [RuAttitudesVersions.V20Large, RuAttitudesVersions.V20Base,
|
|
39
|
-
RuAttitudesVersions.V20BaseNeut, RuAttitudesVersions.V20LargeNeut])
|
|
40
|
-
|
|
41
|
-
doc_provider = RuAttitudesDocumentProvider(version=version,
|
|
42
|
-
keep_doc_ids_only=False,
|
|
43
|
-
doc_id_func=lambda doc_id: doc_id,
|
|
44
|
-
limit=limit)
|
|
45
|
-
|
|
46
|
-
text_opinion_filters = [
|
|
47
|
-
EntityBasedTextOpinionFilter(entity_filter=RuAttitudesEntityFilter()),
|
|
48
|
-
DistanceLimitedTextOpinionFilter(terms_per_context)
|
|
49
|
-
]
|
|
50
|
-
|
|
51
|
-
# Append with the custom filters afterwards.
|
|
52
|
-
if custom_text_opinion_filters is not None:
|
|
53
|
-
text_opinion_filters += custom_text_opinion_filters
|
|
54
|
-
|
|
55
|
-
pipeline = text_opinion_extraction_pipeline(
|
|
56
|
-
annotators=[
|
|
57
|
-
PredefinedTextOpinionAnnotator(doc_provider=doc_provider,
|
|
58
|
-
label_formatter=RuAttitudesLabelFormatter(label_scaler))
|
|
59
|
-
],
|
|
60
|
-
text_opinion_filters=custom_text_opinion_filters,
|
|
61
|
-
get_doc_by_id_func=doc_provider.by_id,
|
|
62
|
-
entity_index_func=lambda brat_entity: brat_entity.ID,
|
|
63
|
-
text_parser=text_parser)
|
|
64
|
-
|
|
65
|
-
return pipeline
|
|
File without changes
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
from arekit.common.data.doc_provider import DocumentProvider
|
|
2
|
-
from arekit.common.synonyms.base import SynonymsCollection
|
|
3
|
-
from arekit.contrib.source.rusentrel.io_utils import RuSentRelVersions
|
|
4
|
-
from arekit.contrib.source.rusentrel.docs_reader import RuSentRelDocumentsReader
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class RuSentrelDocumentProvider(DocumentProvider):
|
|
8
|
-
""" Limitations: Supported only train/test collections format
|
|
9
|
-
"""
|
|
10
|
-
|
|
11
|
-
def __init__(self, version, synonyms):
|
|
12
|
-
assert(isinstance(version, RuSentRelVersions))
|
|
13
|
-
assert(isinstance(synonyms, SynonymsCollection))
|
|
14
|
-
super(RuSentrelDocumentProvider, self).__init__()
|
|
15
|
-
self.__version = version
|
|
16
|
-
self.__synonyms = synonyms
|
|
17
|
-
|
|
18
|
-
def by_id(self, doc_id):
|
|
19
|
-
assert (isinstance(doc_id, int))
|
|
20
|
-
return RuSentRelDocumentsReader.read_document(doc_id=doc_id, synonyms=self.__synonyms, version=self.__version)
|
|
21
|
-
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
from arekit.common.labels.base import NoLabel
|
|
2
|
-
from arekit.common.labels.provider.constant import ConstantLabelProvider
|
|
3
|
-
from arekit.common.opinions.annot.algo.pair_based import PairBasedOpinionAnnotationAlgorithm
|
|
4
|
-
from arekit.common.opinions.annot.algo.predefined import PredefinedOpinionAnnotationAlgorithm
|
|
5
|
-
from arekit.common.opinions.collection import OpinionCollection
|
|
6
|
-
from arekit.common.synonyms.grouping import SynonymsCollectionValuesGroupingProviders
|
|
7
|
-
from arekit.contrib.source.rusentrel.labels_fmt import RuSentRelLabelsFormatter
|
|
8
|
-
from arekit.contrib.source.rusentrel.opinions.collection import RuSentRelOpinions
|
|
9
|
-
from arekit.contrib.source.rusentrel.synonyms import RuSentRelSynonymsCollectionHelper
|
|
10
|
-
from arekit.contrib.utils.pipelines.sources.rusentrel.doc_provider import RuSentrelDocumentProvider
|
|
11
|
-
from arekit.contrib.utils.pipelines.text_opinion.annot.algo_based import AlgorithmBasedTextOpinionAnnotator
|
|
12
|
-
from arekit.contrib.utils.pipelines.text_opinion.extraction import text_opinion_extraction_pipeline
|
|
13
|
-
from arekit.contrib.utils.pipelines.text_opinion.filters.distance_based import DistanceLimitedTextOpinionFilter
|
|
14
|
-
from arekit.contrib.utils.processing.lemmatization.mystem import MystemWrapper
|
|
15
|
-
from arekit.contrib.utils.synonyms.stemmer_based import StemmerBasedSynonymCollection
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def create_text_opinion_extraction_pipeline(rusentrel_version,
|
|
19
|
-
text_parser,
|
|
20
|
-
labels_fmt,
|
|
21
|
-
custom_text_opinion_filters=None,
|
|
22
|
-
no_label=NoLabel(),
|
|
23
|
-
terms_per_context=50,
|
|
24
|
-
dist_in_sentences=0):
|
|
25
|
-
""" Processing pipeline for RuSentRel, which combines:
|
|
26
|
-
- predefined document-level annotation (sentiment labels)
|
|
27
|
-
- automatic annotation of opinions between mentioned named entities (no-label)
|
|
28
|
-
|
|
29
|
-
Original collection paper: arxiv.org/abs/1808.08932
|
|
30
|
-
|
|
31
|
-
version: enum
|
|
32
|
-
Version of the RuSentRel collection.
|
|
33
|
-
terms_per_context: int
|
|
34
|
-
Amount of terms that we consider in between the Object and Subject.
|
|
35
|
-
dist_in_sentences: int
|
|
36
|
-
considering amount of sentences that could be in between Object and Subject.
|
|
37
|
-
"""
|
|
38
|
-
assert(isinstance(labels_fmt, RuSentRelLabelsFormatter))
|
|
39
|
-
assert(isinstance(custom_text_opinion_filters, list) or custom_text_opinion_filters is None)
|
|
40
|
-
|
|
41
|
-
synonyms = StemmerBasedSynonymCollection(
|
|
42
|
-
iter_group_values_lists=RuSentRelSynonymsCollectionHelper.iter_groups(rusentrel_version),
|
|
43
|
-
stemmer=MystemWrapper(),
|
|
44
|
-
is_read_only=False)
|
|
45
|
-
|
|
46
|
-
doc_provider = RuSentrelDocumentProvider(version=rusentrel_version, synonyms=synonyms)
|
|
47
|
-
|
|
48
|
-
text_opinion_filters = [
|
|
49
|
-
DistanceLimitedTextOpinionFilter(terms_per_context)
|
|
50
|
-
]
|
|
51
|
-
|
|
52
|
-
# Append with the custom filters afterwards.
|
|
53
|
-
if custom_text_opinion_filters is not None:
|
|
54
|
-
text_opinion_filters += custom_text_opinion_filters
|
|
55
|
-
|
|
56
|
-
pipeline = text_opinion_extraction_pipeline(
|
|
57
|
-
annotators=[
|
|
58
|
-
predefined_annotator(synonyms=synonyms, labels_fmt=labels_fmt),
|
|
59
|
-
nolabel_annotator(synonyms=synonyms, terms_per_context=terms_per_context,
|
|
60
|
-
dist_in_sentences=dist_in_sentences, no_label=no_label)
|
|
61
|
-
],
|
|
62
|
-
text_opinion_filters=text_opinion_filters,
|
|
63
|
-
get_doc_by_id_func=doc_provider.by_id,
|
|
64
|
-
entity_index_func=lambda brat_entity: brat_entity.ID,
|
|
65
|
-
text_parser=text_parser)
|
|
66
|
-
|
|
67
|
-
return pipeline
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
def nolabel_annotator(synonyms, terms_per_context, dist_in_sentences=0, no_label=NoLabel()):
|
|
71
|
-
""" This is a default annotator, utilized to annotate `neutral`-like attitudes.
|
|
72
|
-
Neutral means that we adopt no-label parameter, and this label might be customized
|
|
73
|
-
to the one required in your studies.
|
|
74
|
-
"""
|
|
75
|
-
return AlgorithmBasedTextOpinionAnnotator(
|
|
76
|
-
annot_algo=PairBasedOpinionAnnotationAlgorithm(dist_in_sents=dist_in_sentences,
|
|
77
|
-
dist_in_terms_bound=terms_per_context,
|
|
78
|
-
label_provider=ConstantLabelProvider(no_label),
|
|
79
|
-
entity_index_func=lambda brat_entity: brat_entity.ID),
|
|
80
|
-
create_empty_collection_func=lambda: OpinionCollection(
|
|
81
|
-
synonyms=synonyms, error_on_duplicates=True, error_on_synonym_end_missed=False),
|
|
82
|
-
value_to_group_id_func=lambda value:
|
|
83
|
-
SynonymsCollectionValuesGroupingProviders.provide_existed_value(synonyms=synonyms, value=value))
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
def predefined_annotator(synonyms, labels_fmt):
|
|
87
|
-
""" This is a annotator-converter of the predefined Document-Level opinions onto text-level one
|
|
88
|
-
"""
|
|
89
|
-
return AlgorithmBasedTextOpinionAnnotator(
|
|
90
|
-
annot_algo=PredefinedOpinionAnnotationAlgorithm(
|
|
91
|
-
lambda doc_id: __get_document_opinions(doc_id=doc_id, synonyms=synonyms, labels_fmt=labels_fmt)),
|
|
92
|
-
create_empty_collection_func=lambda: OpinionCollection(
|
|
93
|
-
synonyms=synonyms, error_on_duplicates=True, error_on_synonym_end_missed=False),
|
|
94
|
-
value_to_group_id_func=lambda value:
|
|
95
|
-
SynonymsCollectionValuesGroupingProviders.provide_existed_value(synonyms=synonyms, value=value))
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
def __get_document_opinions(doc_id, synonyms, labels_fmt):
|
|
99
|
-
""" RuSentRel provides a pre-defined list of Document-Level Opinions.
|
|
100
|
-
Within this function we create the related OpinionCollection by a given doc_id.
|
|
101
|
-
"""
|
|
102
|
-
return OpinionCollection(
|
|
103
|
-
opinions=RuSentRelOpinions.iter_from_doc(
|
|
104
|
-
doc_id=doc_id, labels_fmt=labels_fmt),
|
|
105
|
-
synonyms=synonyms,
|
|
106
|
-
error_on_synonym_end_missed=True,
|
|
107
|
-
error_on_duplicates=True)
|
|
File without changes
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
from arekit.common.data.doc_provider import DocumentProvider
|
|
2
|
-
from arekit.contrib.source.sentinerel.io_utils import SentiNerelVersions
|
|
3
|
-
from arekit.contrib.source.sentinerel.reader import SentiNerelDocReader
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class SentiNERELDocProvider(DocumentProvider):
|
|
7
|
-
""" Document reader for the collection of the RuSentNE competition 2023.
|
|
8
|
-
For more details please follow the following repository:
|
|
9
|
-
github: https://github.com/dialogue-evaluation/RuSentNE-evaluation
|
|
10
|
-
"""
|
|
11
|
-
|
|
12
|
-
def __init__(self, filename_by_id, version):
|
|
13
|
-
""" filename_ids: dict
|
|
14
|
-
Dictionary of {id: filename}, where
|
|
15
|
-
- id: int
|
|
16
|
-
- filename: str
|
|
17
|
-
version: SentiNerelVersions
|
|
18
|
-
Specify the appropriate version of teh SentiNEREL collection.
|
|
19
|
-
"""
|
|
20
|
-
assert(isinstance(filename_by_id, dict))
|
|
21
|
-
assert(isinstance(version, SentiNerelVersions))
|
|
22
|
-
super(SentiNERELDocProvider, self).__init__()
|
|
23
|
-
self.__filename_by_id = filename_by_id
|
|
24
|
-
self.__version = version
|
|
25
|
-
|
|
26
|
-
def by_id(self, doc_id):
|
|
27
|
-
return SentiNerelDocReader.read_document(doc_id=doc_id,
|
|
28
|
-
version=self.__version,
|
|
29
|
-
filename=self.__filename_by_id[doc_id])
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
from arekit.common.entities.base import Entity
|
|
2
|
-
from arekit.common.entities.types import OpinionEntityType
|
|
3
|
-
from arekit.contrib.utils.entities.filter import EntityFilter
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class EntityHelper(object):
|
|
7
|
-
""" Named Entities formatting in text.
|
|
8
|
-
Based on OntoNotes5 collection tags:
|
|
9
|
-
https://catalog.ldc.upenn.edu/LDC2013T19
|
|
10
|
-
"""
|
|
11
|
-
|
|
12
|
-
AGE = "AGE"
|
|
13
|
-
AWARD = "AWARD"
|
|
14
|
-
CITY = "CITY"
|
|
15
|
-
COUNTRY = "COUNTRY"
|
|
16
|
-
CRIME = "CRIME"
|
|
17
|
-
DATE = "DATE"
|
|
18
|
-
DISEASE = "DISEASE"
|
|
19
|
-
DISTRICT = "DISTRICT"
|
|
20
|
-
EVENT = "EVENT"
|
|
21
|
-
FACILITY = "FACILITY"
|
|
22
|
-
FAMILY = "FAMILY"
|
|
23
|
-
IDEOLOGY = "IDEOLOGY"
|
|
24
|
-
LANGUAGE = "LANGUAGE"
|
|
25
|
-
LAW = "LAW"
|
|
26
|
-
LOCATION = "LOCATION"
|
|
27
|
-
MONEY = "MONEY"
|
|
28
|
-
NATIONALITY = "NATIONALITY"
|
|
29
|
-
NUMBER = "NUMBER"
|
|
30
|
-
ORDINAL = "ORDINAL"
|
|
31
|
-
ORGANIZATION = "ORGANIZATION"
|
|
32
|
-
PENALTY = "PENALTY"
|
|
33
|
-
PERCENT = "PERCENT"
|
|
34
|
-
PERSON = "PERSON"
|
|
35
|
-
PRODUCT = "PRODUCT"
|
|
36
|
-
PROFESSION = "PROFESSION"
|
|
37
|
-
RELIGION = "RELIGION"
|
|
38
|
-
STATE_OR_PROVINCE = "STATE_OR_PROVINCE"
|
|
39
|
-
TIME = "TIME"
|
|
40
|
-
WORK_OF_ART = "WORK_OF_ART"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
class SentiNerelEntityFilter(EntityFilter):
|
|
44
|
-
""" Filter, oriented on sentiment related extraction task
|
|
45
|
-
within SentiNEREL dataset.
|
|
46
|
-
"""
|
|
47
|
-
|
|
48
|
-
def is_ignored(self, entity, e_type):
|
|
49
|
-
""" Subject and Object could be one of the following object types:
|
|
50
|
-
[PERSON, ORGANIZATION, COUNTRY, PROFESSION]
|
|
51
|
-
"""
|
|
52
|
-
assert(isinstance(entity, Entity))
|
|
53
|
-
assert(isinstance(e_type, OpinionEntityType))
|
|
54
|
-
|
|
55
|
-
supported = [EntityHelper.PERSON, EntityHelper.ORGANIZATION, EntityHelper.COUNTRY, EntityHelper.PROFESSION]
|
|
56
|
-
|
|
57
|
-
if e_type == OpinionEntityType.Subject:
|
|
58
|
-
return entity.Type not in supported
|
|
59
|
-
if e_type == OpinionEntityType.Object:
|
|
60
|
-
return entity.Type not in supported
|
|
61
|
-
else:
|
|
62
|
-
return True
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
from arekit.common.data.doc_provider import DocumentProvider
|
|
2
|
-
from arekit.common.experiment.data_type import DataType
|
|
3
|
-
from arekit.common.labels.base import NoLabel
|
|
4
|
-
from arekit.common.labels.provider.constant import ConstantLabelProvider
|
|
5
|
-
from arekit.common.opinions.annot.algo.pair_based import PairBasedOpinionAnnotationAlgorithm
|
|
6
|
-
from arekit.common.opinions.collection import OpinionCollection
|
|
7
|
-
from arekit.common.synonyms.base import SynonymsCollection
|
|
8
|
-
from arekit.common.synonyms.grouping import SynonymsCollectionValuesGroupingProviders
|
|
9
|
-
from arekit.contrib.source.sentinerel.io_utils import SentiNerelVersions, SentiNerelIOUtils
|
|
10
|
-
from arekit.contrib.utils.pipelines.sources.sentinerel.doc_provider import SentiNERELDocProvider
|
|
11
|
-
from arekit.contrib.utils.pipelines.sources.sentinerel.labels_fmt import SentiNERELSentimentLabelFormatter
|
|
12
|
-
from arekit.contrib.utils.pipelines.text_opinion.annot.algo_based import AlgorithmBasedTextOpinionAnnotator
|
|
13
|
-
from arekit.contrib.utils.pipelines.text_opinion.annot.predefined import PredefinedTextOpinionAnnotator
|
|
14
|
-
from arekit.contrib.utils.pipelines.text_opinion.extraction import text_opinion_extraction_pipeline
|
|
15
|
-
from arekit.contrib.utils.pipelines.text_opinion.filters.distance_based import DistanceLimitedTextOpinionFilter
|
|
16
|
-
from arekit.contrib.utils.processing.lemmatization.mystem import MystemWrapper
|
|
17
|
-
from arekit.contrib.utils.sources.sentinerel.text_opinion.prof_per_org_filter import \
|
|
18
|
-
ProfessionAsCharacteristicSentimentTextOpinionFilter
|
|
19
|
-
from arekit.contrib.utils.synonyms.stemmer_based import StemmerBasedSynonymCollection
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def create_text_opinion_extraction_pipeline(sentinerel_version,
|
|
23
|
-
text_parser,
|
|
24
|
-
custom_text_opinion_filters=None,
|
|
25
|
-
label_formatter=SentiNERELSentimentLabelFormatter(),
|
|
26
|
-
no_label=NoLabel(),
|
|
27
|
-
terms_per_context=50,
|
|
28
|
-
doc_provider=None,
|
|
29
|
-
dist_in_sentences=0,
|
|
30
|
-
docs_limit=None):
|
|
31
|
-
""" This is a main pipeline which generates the samples for a SentiNEREL documents.
|
|
32
|
-
SentiNEREL is a collection that becomes a part of the:
|
|
33
|
-
1. Attitude extraction studies (AREkit focused studies):
|
|
34
|
-
https://github.com/nicolay-r/SentiNEREL-attitude-extraction
|
|
35
|
-
2. RuSentNE-2023 competitions under CODALAB platform (github page):
|
|
36
|
-
https://github.com/dialogue-evaluation/RuSentNE-evaluation
|
|
37
|
-
|
|
38
|
-
Parameters:
|
|
39
|
-
sentinerel_version: enum
|
|
40
|
-
Version of the SentiNEREL collection.
|
|
41
|
-
text_parser: Is the way of how do we process the text.
|
|
42
|
-
doc_provider: DocumentProvider or None
|
|
43
|
-
In case of None we consider the default initialization.
|
|
44
|
-
label_formatter:
|
|
45
|
-
Formatter for labels which allows to: limit set of labels, and perform its conversion from
|
|
46
|
-
string to actual python type.
|
|
47
|
-
terms_per_context: int
|
|
48
|
-
Amount of terms that we consider in between the Object and Subject.
|
|
49
|
-
|
|
50
|
-
Returns: dict, (data_folding) optional
|
|
51
|
-
pipelines per every type.
|
|
52
|
-
"""
|
|
53
|
-
assert(isinstance(sentinerel_version, SentiNerelVersions))
|
|
54
|
-
assert(isinstance(doc_provider, DocumentProvider) or doc_provider is None)
|
|
55
|
-
assert(isinstance(custom_text_opinion_filters, list) or custom_text_opinion_filters is None)
|
|
56
|
-
|
|
57
|
-
data_folding = None
|
|
58
|
-
|
|
59
|
-
if doc_provider is None:
|
|
60
|
-
# Default Initialization.
|
|
61
|
-
filenames_by_ids, data_folding = SentiNerelIOUtils.read_dataset_split(version=sentinerel_version,
|
|
62
|
-
docs_limit=docs_limit)
|
|
63
|
-
doc_provider = SentiNERELDocProvider(filename_by_id=filenames_by_ids,
|
|
64
|
-
version=sentinerel_version)
|
|
65
|
-
|
|
66
|
-
train_neut_annot = create_nolabel_text_opinion_annotator(terms_per_context=terms_per_context,
|
|
67
|
-
dist_in_sents=dist_in_sentences,
|
|
68
|
-
no_label=no_label)
|
|
69
|
-
test_neut_annot = create_nolabel_text_opinion_annotator(terms_per_context=terms_per_context,
|
|
70
|
-
dist_in_sents=dist_in_sentences,
|
|
71
|
-
no_label=no_label)
|
|
72
|
-
|
|
73
|
-
text_opinion_filters = [
|
|
74
|
-
ProfessionAsCharacteristicSentimentTextOpinionFilter(),
|
|
75
|
-
DistanceLimitedTextOpinionFilter(terms_per_context)
|
|
76
|
-
]
|
|
77
|
-
|
|
78
|
-
# Append with the custom filters afterwards.
|
|
79
|
-
if custom_text_opinion_filters is not None:
|
|
80
|
-
text_opinion_filters += custom_text_opinion_filters
|
|
81
|
-
|
|
82
|
-
predefined_annot = PredefinedTextOpinionAnnotator(doc_provider, label_formatter)
|
|
83
|
-
|
|
84
|
-
pipelines = {
|
|
85
|
-
DataType.Train: create_main_pipeline(text_parser=text_parser,
|
|
86
|
-
doc_provider=doc_provider,
|
|
87
|
-
annotators=[
|
|
88
|
-
predefined_annot,
|
|
89
|
-
train_neut_annot
|
|
90
|
-
],
|
|
91
|
-
text_opinion_filters=text_opinion_filters),
|
|
92
|
-
DataType.Test: create_main_pipeline(text_parser=text_parser,
|
|
93
|
-
doc_provider=doc_provider,
|
|
94
|
-
annotators=[
|
|
95
|
-
test_neut_annot
|
|
96
|
-
],
|
|
97
|
-
text_opinion_filters=text_opinion_filters),
|
|
98
|
-
DataType.Etalon: create_etalon_pipeline(text_parser=text_parser,
|
|
99
|
-
doc_provider=doc_provider,
|
|
100
|
-
predefined_annot=predefined_annot,
|
|
101
|
-
text_opinion_filters=text_opinion_filters),
|
|
102
|
-
DataType.Dev: create_etalon_with_no_label_pipeline(text_parser=text_parser,
|
|
103
|
-
doc_provider=doc_provider,
|
|
104
|
-
annotators=[
|
|
105
|
-
predefined_annot,
|
|
106
|
-
train_neut_annot
|
|
107
|
-
],
|
|
108
|
-
text_opinion_filters=text_opinion_filters),
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
# In the case when we setup a default data-folding.
|
|
112
|
-
# There is a need to provide it, due to the needs in further.
|
|
113
|
-
if data_folding is not None:
|
|
114
|
-
return pipelines, data_folding
|
|
115
|
-
|
|
116
|
-
return pipelines
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
def create_nolabel_text_opinion_annotator(terms_per_context, no_label, dist_in_sents=0, synonyms=None):
|
|
120
|
-
""" This is a core annotator, which provides all entity pairs.
|
|
121
|
-
Could be revealed from the document.
|
|
122
|
-
|
|
123
|
-
Parameters:
|
|
124
|
-
terms_per_context: int
|
|
125
|
-
Amount of terms that we consider in between the Object and Subject.
|
|
126
|
-
dist_in_sents: int
|
|
127
|
-
Distance in sentences in between the objects.
|
|
128
|
-
"""
|
|
129
|
-
assert(isinstance(terms_per_context, int))
|
|
130
|
-
assert(isinstance(synonyms, SynonymsCollection) or synonyms is None)
|
|
131
|
-
assert(isinstance(dist_in_sents, int))
|
|
132
|
-
|
|
133
|
-
if synonyms is None:
|
|
134
|
-
synonyms = StemmerBasedSynonymCollection(stemmer=MystemWrapper(), is_read_only=False)
|
|
135
|
-
|
|
136
|
-
return AlgorithmBasedTextOpinionAnnotator(
|
|
137
|
-
value_to_group_id_func=lambda value:
|
|
138
|
-
SynonymsCollectionValuesGroupingProviders.provide_existed_or_register_missed_value(
|
|
139
|
-
synonyms=synonyms, value=value),
|
|
140
|
-
annot_algo=PairBasedOpinionAnnotationAlgorithm(
|
|
141
|
-
dist_in_sents=dist_in_sents,
|
|
142
|
-
dist_in_terms_bound=terms_per_context,
|
|
143
|
-
label_provider=ConstantLabelProvider(no_label),
|
|
144
|
-
entity_index_func=lambda brat_entity: brat_entity.ID),
|
|
145
|
-
create_empty_collection_func=lambda: OpinionCollection(
|
|
146
|
-
synonyms=synonyms,
|
|
147
|
-
error_on_duplicates=True,
|
|
148
|
-
error_on_synonym_end_missed=False))
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
def create_main_pipeline(text_parser, doc_provider, annotators, text_opinion_filters):
|
|
152
|
-
""" Train pipeline is based on the predefined annotations and
|
|
153
|
-
automatic annotations of other pairs with a NoLabel.
|
|
154
|
-
"""
|
|
155
|
-
return text_opinion_extraction_pipeline(
|
|
156
|
-
get_doc_by_id_func=doc_provider.by_id,
|
|
157
|
-
text_parser=text_parser,
|
|
158
|
-
annotators=annotators,
|
|
159
|
-
entity_index_func=lambda brat_entity: brat_entity.ID,
|
|
160
|
-
text_opinion_filters=text_opinion_filters)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
def create_etalon_pipeline(text_parser, doc_provider, predefined_annot, text_opinion_filters):
|
|
164
|
-
""" We adopt exact the same pipeline as for training data,
|
|
165
|
-
but we do not perform "NoLabel" annotation.
|
|
166
|
-
(we are interested only in sentiment attitudes).
|
|
167
|
-
"""
|
|
168
|
-
return create_main_pipeline(text_parser=text_parser,
|
|
169
|
-
doc_provider=doc_provider,
|
|
170
|
-
annotators=[predefined_annot],
|
|
171
|
-
text_opinion_filters=text_opinion_filters)
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
def create_etalon_with_no_label_pipeline(annotators, text_parser, doc_provider, text_opinion_filters):
|
|
175
|
-
""" We adopt exact the same pipeline as for training data.
|
|
176
|
-
"""
|
|
177
|
-
return create_main_pipeline(text_parser=text_parser,
|
|
178
|
-
doc_provider=doc_provider,
|
|
179
|
-
annotators=annotators,
|
|
180
|
-
text_opinion_filters=text_opinion_filters)
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
from arekit.common.labels.base import NoLabel
|
|
2
|
-
from arekit.common.labels.str_fmt import StringLabelsFormatter
|
|
3
|
-
from arekit.contrib.source.sentinerel import labels
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class SentiNERELAnyLabelFormatter(StringLabelsFormatter):
|
|
7
|
-
|
|
8
|
-
def __init__(self):
|
|
9
|
-
|
|
10
|
-
stol = {
|
|
11
|
-
"OPINION_BELONGS_TO": labels.OpinionBelongsTo,
|
|
12
|
-
"OPINION_RELATES_TO": labels.OpinionRelatesTo,
|
|
13
|
-
"NEG_EFFECT_FROM": labels.NegEffectFrom,
|
|
14
|
-
"POS_EFFECT_FROM": labels.PosEffectFrom,
|
|
15
|
-
"NEG_STATE_FROM": labels.NegStateFrom,
|
|
16
|
-
"POS_STATE_FROM": labels.PosStateFrom,
|
|
17
|
-
"NEGATIVE_TO": labels.NegativeTo,
|
|
18
|
-
"POSITIVE_TO": labels.PositiveTo,
|
|
19
|
-
"STATE_BELONGS_TO": labels.StateBelongsTo,
|
|
20
|
-
"POS_AUTHOR_FROM": labels.PosAuthorFrom,
|
|
21
|
-
"NEG_AUTHOR_FROM": labels.NegAuthorFrom,
|
|
22
|
-
"ALTERNATIVE_NAME": labels.AlternativeName,
|
|
23
|
-
"ORIGINS_FROM": labels.OriginsFrom
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
super(SentiNERELAnyLabelFormatter, self).__init__(stol=stol)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class SentiNERELSentimentLabelFormatter(StringLabelsFormatter):
|
|
30
|
-
|
|
31
|
-
def __init__(self):
|
|
32
|
-
stol = {
|
|
33
|
-
"NEGATIVE_TO": labels.NegativeTo,
|
|
34
|
-
"POSITIVE_TO": labels.PositiveTo,
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
super(SentiNERELSentimentLabelFormatter, self).__init__(stol=stol)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class SentiNERELPosNegNeuRelationsLabelFormatter(StringLabelsFormatter):
|
|
41
|
-
|
|
42
|
-
def __init__(self):
|
|
43
|
-
|
|
44
|
-
stol = {
|
|
45
|
-
"NEUTRAL": NoLabel,
|
|
46
|
-
"NEGATIVE_TO": labels.NegativeTo,
|
|
47
|
-
"POSITIVE_TO": labels.PositiveTo,
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
super(SentiNERELPosNegNeuRelationsLabelFormatter, self).__init__(stol=stol)
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
from arekit.common.data.doc_provider import DocumentProvider
|
|
2
|
-
from arekit.common.labels.str_fmt import StringLabelsFormatter
|
|
3
|
-
from arekit.common.docs.parsed.base import ParsedDocument
|
|
4
|
-
from arekit.common.docs.parsed.providers.base import BaseParsedDocumentServiceProvider
|
|
5
|
-
from arekit.common.docs.parsed.providers.entity_service import EntityServiceProvider
|
|
6
|
-
from arekit.common.docs.parsed.service import ParsedDocumentService
|
|
7
|
-
from arekit.common.opinions.annot.base import BaseOpinionAnnotator
|
|
8
|
-
from arekit.contrib.source.brat.doc import BratDocument
|
|
9
|
-
from arekit.contrib.source.brat.opinions.converter import BratRelationConverter
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class PredefinedTextOpinionAnnotator(BaseOpinionAnnotator):
|
|
13
|
-
""" Brat-based text-opinion annotator (converter).
|
|
14
|
-
It converts the pre-annotated Relations from BRAT-documents to TextOpinions
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
def __init__(self, doc_provider, label_formatter, keep_any_type=False, entity_index_func=None):
|
|
18
|
-
"""
|
|
19
|
-
get_doc_func:
|
|
20
|
-
func(doc_id)
|
|
21
|
-
|
|
22
|
-
label_formatter: String Labels Formatter
|
|
23
|
-
required for conversion.
|
|
24
|
-
|
|
25
|
-
keep_any_type: bool
|
|
26
|
-
flag that defines whether there is a need to consider all the text opinions
|
|
27
|
-
or only one that supported by label formatter.
|
|
28
|
-
|
|
29
|
-
entity_index_func: is a way of how we provide an external entity ID
|
|
30
|
-
fund(entity) -> ID
|
|
31
|
-
"""
|
|
32
|
-
assert(isinstance(doc_provider, DocumentProvider))
|
|
33
|
-
assert(isinstance(label_formatter, StringLabelsFormatter))
|
|
34
|
-
assert(callable(entity_index_func) or entity_index_func is None)
|
|
35
|
-
super(PredefinedTextOpinionAnnotator, self).__init__()
|
|
36
|
-
|
|
37
|
-
self.__doc_provider = doc_provider
|
|
38
|
-
self.__label_formatter = label_formatter
|
|
39
|
-
self.__keep_any_type = keep_any_type
|
|
40
|
-
self.__entity_index_func = (lambda brat_entity: brat_entity.ID) if \
|
|
41
|
-
entity_index_func is None else entity_index_func
|
|
42
|
-
|
|
43
|
-
@staticmethod
|
|
44
|
-
def __convert_entity_id(doc, origin_entity_id, esp):
|
|
45
|
-
assert(isinstance(doc, BratDocument))
|
|
46
|
-
assert(isinstance(origin_entity_id, int))
|
|
47
|
-
assert(isinstance(esp, BaseParsedDocumentServiceProvider))
|
|
48
|
-
|
|
49
|
-
if not doc.contains_entity(origin_entity_id):
|
|
50
|
-
# Due to the complexity of entities, some entities might be nested.
|
|
51
|
-
# Therefore the latter, some entities might be discarded.
|
|
52
|
-
return None
|
|
53
|
-
|
|
54
|
-
origin_entity = doc.get_entity_by_id(origin_entity_id)
|
|
55
|
-
|
|
56
|
-
if not esp.contains_entity(origin_entity):
|
|
57
|
-
return None
|
|
58
|
-
|
|
59
|
-
document_entity = esp.get_document_entity(origin_entity)
|
|
60
|
-
return document_entity.IdInDocument
|
|
61
|
-
|
|
62
|
-
def _annot_collection_core(self, parsed_doc):
|
|
63
|
-
assert(isinstance(parsed_doc, ParsedDocument))
|
|
64
|
-
|
|
65
|
-
pns = ParsedDocumentService(parsed_doc=parsed_doc, providers=[
|
|
66
|
-
EntityServiceProvider(self.__entity_index_func)
|
|
67
|
-
])
|
|
68
|
-
esp = pns.get_provider(EntityServiceProvider.NAME)
|
|
69
|
-
doc = self.__doc_provider.by_id(parsed_doc.RelatedDocID)
|
|
70
|
-
|
|
71
|
-
for brat_relation in doc.Relations:
|
|
72
|
-
|
|
73
|
-
if self.__label_formatter.supports_value(brat_relation.Type) or self.__keep_any_type:
|
|
74
|
-
|
|
75
|
-
text_opinion = BratRelationConverter.to_text_opinion(
|
|
76
|
-
brat_relation=brat_relation,
|
|
77
|
-
doc_id=parsed_doc.RelatedDocID,
|
|
78
|
-
label_formatter=self.__label_formatter)
|
|
79
|
-
|
|
80
|
-
internal_opinion = text_opinion.try_convert(
|
|
81
|
-
other=text_opinion,
|
|
82
|
-
convert_entity_id_func=lambda origin_id: PredefinedTextOpinionAnnotator.__convert_entity_id(
|
|
83
|
-
doc=doc, origin_entity_id=origin_id, esp=esp))
|
|
84
|
-
|
|
85
|
-
if internal_opinion is None:
|
|
86
|
-
continue
|
|
87
|
-
|
|
88
|
-
yield internal_opinion
|
|
File without changes
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
from enum import IntEnum
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class PartOfSpeechType(IntEnum):
|
|
5
|
-
|
|
6
|
-
NOUN = 1
|
|
7
|
-
ADV = 2
|
|
8
|
-
ADVPRO = 3
|
|
9
|
-
ANUM = 4
|
|
10
|
-
APRO = 5
|
|
11
|
-
COM = 6
|
|
12
|
-
CONJ = 7
|
|
13
|
-
INTJ = 8
|
|
14
|
-
NUM = 9
|
|
15
|
-
PART = 10
|
|
16
|
-
PR = 11
|
|
17
|
-
ADJ = 12
|
|
18
|
-
SPRO = 13
|
|
19
|
-
VERB = 14
|
|
20
|
-
|
|
21
|
-
Unknown = 15
|
|
22
|
-
|
|
23
|
-
Empty = 16
|
|
File without changes
|