Permalink
Browse files

Porting Semantic Role Labeling engine from v1 and add unit test cover…

…age #4
  • Loading branch information...
leonardossz committed May 10, 2017
1 parent 425cb2f commit dd4244173a88c83fdb51fa39972fd610bb617679
@@ -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()));
}
}
@@ -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);
@@ -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);
@@ -151,7 +151,8 @@ stargraph.rules = {
".* (their) .*",
".* (the) .*",
".* (of) .*",
".*(TYPE_1).*"
".*(TYPE_1).*",
".*(STOP_1).*"
]
syntatic-pattern.en = [
@@ -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) .*"
]
}

0 comments on commit dd42441

Please sign in to comment.