-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcollection.py
30 lines (26 loc) · 1.38 KB
/
collection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from arekit.contrib.source.rusentrel.const import POS_LABEL_STR, NEG_LABEL_STR
from arekit.contrib.source.rusentrel.io_utils import RuSentRelIOUtils, RuSentRelVersions
from arekit.contrib.source.rusentrel.labels_fmt import RuSentRelLabelsFormatter
from arekit.contrib.source.rusentrel.opinions.provider import RuSentRelOpinionCollectionProvider
class RuSentRelOpinionCollection:
"""
Collection of sentiment opinions between entities
"""
@staticmethod
def iter_opinions_from_doc(doc_id, labels_fmt, version=RuSentRelVersions.V11):
""" doc_id:
synonyms: None or SynonymsCollection
None corresponds to the related synonym collection from RuSentRel collection.
version: RuSentrelVersions enum
"""
assert(isinstance(version, RuSentRelVersions))
assert(isinstance(labels_fmt, RuSentRelLabelsFormatter))
assert(labels_fmt.supports_value(POS_LABEL_STR))
assert(labels_fmt.supports_value(NEG_LABEL_STR))
return RuSentRelIOUtils.iter_from_zip(
inner_path=RuSentRelIOUtils.get_sentiment_opin_filepath(index=doc_id, version=version),
process_func=lambda input_file: RuSentRelOpinionCollectionProvider._iter_opinions_from_file(
input_file=input_file,
labels_formatter=labels_fmt,
error_on_non_supported=True),
version=version)