Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion treedlib/features.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from treedlib.templates import *
import lxml.etree as et

def compile_relation_feature_generator(dictionaries=None, opts={}):
def compile_relation_feature_generator(dictionaries=None, opts={}, is_multary=False):
"""
Given optional arguments, returns a generator function which accepts an xml root
and two lists of mention indexes, and will generate relation features for this relation

Optional args are:
* dictionaries: should be a dictionary of lists of phrases, where the key is the dict name
* opts: see defaults above
* is_multary: whether to use multiple mentions or binary mentions
"""
# TODO: put globals into opts
#BASIC_ATTRIBS_REL = ['word', 'lemma', 'pos', 'ner', 'dep_label']
Expand Down Expand Up @@ -66,6 +67,8 @@ def compile_relation_feature_generator(dictionaries=None, opts={}):
templates.append(DictionaryIntersect(SeqBetween(), d_name, d))

# return generator function
if is_multary:
return Compile(templates).apply_multary_relation
return Compile(templates).apply_relation

"""
Expand Down
3 changes: 3 additions & 0 deletions treedlib/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,5 +428,8 @@ def apply_mention(self, root, mention_idxs, dict_sub={}, stopwords=None):
def apply_relation(self, root, mention1_idxs, mention2_idxs, dict_sub={}, stopwords=None):
return self.apply(root, [mention1_idxs, mention2_idxs], dict_sub=dict_sub, stopwords=stopwords)

def apply_multary_relation(self, root, mentions, dict_sub={}, stopwords=None):
return self.apply(root, mentions, dict_sub=dict_sub, stopwords=stopwords)

def __repr__(self):
return '\n'.join(str(op) for op in self._iterops())