Skip to content

Commit

Permalink
Porting Semantic Role Labeling engine from v1 and add unit test cover…
Browse files Browse the repository at this point in the history
…age #4
  • Loading branch information
Leonardo Souza committed May 10, 2017
1 parent 425cb2f commit dd42441
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private void resolvePredicate(InstanceEntity pivot, DataModelBinding binding, SP
ModifiableSearchParams searchParams = ModifiableSearchParams.create(dbId).term(binding.getTerm());
ModifiableRankParams rankParams = ParamsBuilder.word2vec();
Scores scores = searcher.pivotedSearch(pivot, searchParams, rankParams);
builder.add(binding, scores.stream().limit(3).collect(Collectors.toList()));
builder.add(binding, scores.stream().limit(6).collect(Collectors.toList()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,16 @@ AnalysisStep resolve(DataModelTypePattern rule) {

if (matches(rulePattern)) {
String newQuestionStr;
String newPosTagStr = posTagStr;
String newPosTagStr;

if (rule.isLexical()) {
String placeHolder = createPlaceholder(questionStr, modelType);
Replacement replacement = replace(rulePattern, questionStr, placeHolder);
newQuestionStr = replacement.value;

String subPosStr = findSubPosStr(replacement);
Replacement posTagReplacement = replace(subPosStr, posTagStr, placeHolder);
newPosTagStr = posTagReplacement.value;
}
else {
String placeHolder = createPlaceholder(posTagStr, modelType);
Expand Down Expand Up @@ -145,6 +149,24 @@ private String findSubStr(Replacement replacement) {
return subStr;
}

private String findSubPosStr(Replacement replacement) {
String[] capture = Objects.requireNonNull(replacement).capture.split("\\s");
int startIdx = 0;
String subPosStr = null;
for (Word w : annotated) {
if (w.getText().equals(capture[0])) {
subPosStr = annotated.stream()
.skip(startIdx)
.limit(capture.length)
.map(word -> word.getPosTag().getTag()).collect(Collectors.joining(" "));
break;
}
startIdx++;
}

return subPosStr;
}

private boolean matches(Pattern pattern) {
Matcher m1 = pattern.matcher(posTagStr);
Matcher m2 = pattern.matcher(questionStr);
Expand Down
41 changes: 24 additions & 17 deletions stargraph-core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ stargraph.rules = {
".* (their) .*",
".* (the) .*",
".* (of) .*",
".*(TYPE_1).*"
".*(TYPE_1).*",
".*(STOP_1).*"
]

syntatic-pattern.en = [
Expand All @@ -162,24 +163,30 @@ stargraph.rules = {
#
# The order is relevant. Split the array if need to interleave rules.

{
STOP: [
".* (did) .*"
]
}

{
OPERATION: [
"same type as",
"same",
"second highest",
"largest",
"highest after",
"first",
"more than",
"less than",
"earlier than",
"between",
"more",
"less",
"most",
"past",
"still",
"also"
".* (same type as) .*",
".* (same) .*",
".* (second highest) .*",
".* (largest) .*",
".* (highest after) .*",
".* (first) .*",
".* (more than) .*",
".* (less than) .*",
".* (earlier than) .*",
".* (between) .*",
".* (more) .*",
".* (less) .*",
".* (most) .*",
".* (past) .*",
".* (still) .*",
".* (also) .*"
]
}

Expand Down

0 comments on commit dd42441

Please sign in to comment.