Skip to content

Commit

Permalink
improve qg with RE rules
Browse files Browse the repository at this point in the history
  • Loading branch information
R1G4T0N1 committed Apr 23, 2020
1 parent ff65507 commit 0673726
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 181 deletions.
20 changes: 15 additions & 5 deletions qg.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#Controls how far RE goes to detect relationships for each named entity
#Increasing may lead to more relationships at the cost of increased runtime
RE_GRANULARITY = 10
RE_GRANULARITY = 5

#What portion of the generated questions should be binary?
BINARY_RATIO = 2/7
Expand Down Expand Up @@ -212,8 +212,13 @@ def main(_filepath, _N):
best_relationship = Relationship(None,None,"NO TYPE",0.0)

for j in range(max(0,i-RE_GRANULARITY), min(ne_count,i+RE_GRANULARITY)):

entity2 = entities[j]

text_startchar = min(entity1.start_char, entity2.start_char)
text_endchar = max(entity1.end_char, entity2.end_char)
text_excerpt = text[text_startchar:text_endchar]

if(question_count>question_limit):
break

Expand All @@ -227,18 +232,23 @@ def main(_filepath, _N):
continue

question_topics.add((entity1,entity2))
(_kind, _score) = nre_qg.infer(text, entity1.start_char \

(_kind, _score) = nre_qg.infer(text_excerpt, entity1.start_char \
, entity1.end_char, entity2.start_char \
, entity2.end_char)

if(_score>best_relationship.score):
best_relationship = Relationship(entity1,entity2,_kind,_score)
best_relationship.entity1 = entity1
best_relationship.entity2 = entity2
best_relationship.kind = _kind
best_relationship.score = _score
#best_relationship = Relationship(entity1,entity2,_kind,_score)

if(best_relationship.score>0.0):
question = relationship_to_question(best_relationship)
if(question.score>0.0):
print(relationship_to_question(best_relationship).text)
print(relationship_to_question(best_relationship).text.replace("'s",""))
question_count+=1

return


Expand Down
Loading

0 comments on commit 0673726

Please sign in to comment.