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 c731849 commit 425cb2f
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;

import static net.stargraph.query.InteractionMode.NLI;
Expand Down Expand Up @@ -135,10 +132,10 @@ private QueryResponse nliQuery(String userQuery, Language language) {
if (!vars.isEmpty()) {
AnswerSetResponse answerSet = new AnswerSetResponse(NLI, userQuery, queryBuilder);

List<LabeledEntity> expanded = vars.get("VAR_1").stream()
.map(e -> namespace.expand(e)).collect(Collectors.toList());
Set<LabeledEntity> expanded = vars.get("VAR_1").stream()
.map(e -> namespace.expand(e)).collect(Collectors.toSet());

answerSet.setShortAnswer(expanded); // convention, answer must be bound to the first var
answerSet.setShortAnswer(new ArrayList<>(expanded)); // convention, answer must be bound to the first var
answerSet.setMappings(queryBuilder.getMappings());
answerSet.setSPARQLQuery(sparqlQueryStr);
return answerSet;
Expand Down
193 changes: 98 additions & 95 deletions stargraph-core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ stargraph.rules = {
"^(How) .+$",
"^(Give me a list of) .+$",
"^(Give me all) .+$",
"^(Give me the) .+$",
"^(Give me) .+$",
"^(Show me) .+$",
"^(Is there) .+$",
Expand Down Expand Up @@ -133,24 +134,24 @@ stargraph.rules = {
"^(Did) .+$",
"^(did) .+$",
"^(does) .+$",
".*(other).*",
"^(How often) .+$",
"^(Which) .+$",
"^(When) .+$",
"^(Under which) .+$",
"^(To which) .+$",
"^(Was) .+$",
".*(was).*",
".*(are).*",
".*(list of).*",
".+ (all) .+",
".*(some).*",
".*(me).*",
".*(there).*",
".*(their).*",
".*(the).*",
".*(of).*",
".*(TYPE_1).+"
".* (other) .*",
".* (was) .*",
".* (are) .*",
".* (list of) .*",
".* (all) .*",
".* (some) .*",
".* (me) .*",
".* (there) .*",
".* (their) .*",
".* (the) .*",
".* (of) .*",
".*(TYPE_1).*"
]

syntatic-pattern.en = [
Expand Down Expand Up @@ -184,39 +185,39 @@ stargraph.rules = {

{
OPERATION: [
"JJR IN",
"JJ JJS",
"JJS"
".* (JJR IN) .*",
".* (JJ JJS) .*",
".* (JJS) .*"
]
}

{
INSTANCE: [
".*IN DT (NNP NNPS CC NNP NNP).+$",
".*VBD (DT NN IN DT NN IN NNP).+$",
".*VBD (NNP , NNP CC NNP) VB.+$",
".*IN (NNP , NNP).+$",
".*VBD (NNP CC NNP).+$",
".*IN (NNP CC NNP).+$",
"NNP IN NNPS NNP",
"NNP NNP IN NNP",
"NNP NNP PRP",
"NNP IN NNP",
".+(NNP NNP NNP).*$",
"JJ NNP NNP",
"JJ NNP",
"NNP NNP CD",
"NNP CD NNP",
".+(NNP NNP).*$",
"JJ INSTANCE",
"NNP CD"
".*IN DT (NNP NNPS CC NNP NNP).*",
".*VBD (DT NN IN DT NN IN NNP).*",
".*VBD (NNP , NNP CC NNP) VB.*",
".*IN (NNP , NNP).*",
".*VBD (NNP CC NNP).*",
".*IN (NNP CC NNP).*",
".*(NNP IN NNPS NNP).*",
".*(NNP NNP IN NNP).*",
".*(NNP NNP PRP).*",
".*(NNP IN NNP).*",
".*(NNP NNP NNP).*",
".*(JJ NNP NNP).*",
".*(JJ NNP).*",
".*(NNP NNP CD).*",
".*(NNP CD NNP).*",
".*(NNP NNP).*",
".*(JJ INSTANCE).*",
".*(NNP CD).*"
]
}

{
CLASS: [
".*WDT (NNP NNS) .+$",
".*WDT (NNP NN) .+$",
".*WDT (NNP NNS).*",
".*WDT (NNP NN).*",
]
}

Expand All @@ -229,124 +230,126 @@ stargraph.rules = {

{
CLASS: [
"NNS IN JJ NN",
"NN IN JJ NN",
"JJ NNS NNS",
"JJ NN NNS",
"NN NN NNS",
"NN NN NN"
".*(NNS IN JJ NN).*",
".*(NN IN JJ NN).*",
".*(JJ NNS NNS).*",
".*(JJ NN NNS).*",
".*(NN NN NNS).*",
".*(NN NN NN).*"
]
}

{
ATCLASS: [
".*WDT (JJ NNS) .+$",
".*WDT (JJ NN) .+$"
".*WDT (JJ NNS).*",
".*WDT (JJ NN).*"
]
}

{
CLASS: [
".*DT (NNS) IN .+$",
".*DT (NN) IN .+$"
".*DT (NNS) IN.*",
".*DT (NN) IN.*"
]
}

{
TYPE: [
".+(is the) .+$",
"are the",
"a type"
".* (is the) .*",
".* (are the) .*",
".* (a type) .*"
]
}

{
PROPERTY: [
"VBZ VBN VBN",
"VBZ VBN VBN",
"VBG TO VB",
"VBP VBN",
"VBD VBN",
"VBP NN",
"POS NNS NNS",
"POS NN NN",
"POS NN",
".*(VBZ VBN VBN).*",
".*(VBZ VBN VBN).*",
".*(VBG TO VB).*",
".*(VBP VBN).*",
".*(VBD VBN).*",
".*(VBP NN).*",
".*(POS NNS NNS).*",
".*(POS NN NN).*",
".*(POS NN).*",
]
}

{
CLASS: [
".*DT (NN) INSTANCE .+$"
".*DT (NN) INSTANCE.*"
]
}

{
ATCLASS: [
".*WDT (NNS) .+$",
".*WDT (NN) .+$"
".* WDT (NNS).*",
".* WDT (NN).*"
]
}

{
PROPERTY: [
".*(VBD NN NNS) IN .+$",
".* CD (NNS) .+$",
".* CD (NN) .+$",
".+(VBG).+$",
".+(VBN).+$",
".+(VBP).+$",
".+(VBD).+$",
".+(VBZ).+$",
".+(VB).+$"
".+(JJ).+$"
".*(VBD NN NNS) IN.*",
".*CD (NNS).*",
".*CD (NN).*",
".*(VBG).*",
".*(VBN).*",
".*(VBP).*",
".*(VBD).*",
".*(VBZ).*",
".*(VB).*"
".*(JJ).*"
]
}

{
POS: ["POS"]
POS: [
".*(POS).*"
]
}

{
CLASS: [
"JJ JJ NNS",
"JJ JJ NN",
".*WDT (NNP NNP NN).+$",
".*DT (JJ NN IN NN) VB.+$",
".*DT (JJ NN IN NNP) VB.+$",
".*VBZ DT (JJ NNP NN).+$",
".*DT (NNP NN) VB.+$"
".*(JJ JJ NNS).*",
".*(JJ JJ NN).*",
".*WDT (NNP NNP NN).*",
".*DT (JJ NN IN NN) VB.*",
".*DT (JJ NN IN NNP) VB.*",
".*VBZ DT (JJ NNP NN).*",
".*DT (NNP NN) VB.*"
]
}

{
ATCLASS: [
".*WDT (NNP NNS).+$",
".*WDT (NNP NN).+$"
".*WDT (NNP NNS).*",
".*WDT (NNP NN).*"
]
}

{
CLASS: [
".*IN (NN) .+$",
"NNP NNP NN",
"NNP NN NN",
"NNP NNS",
"NN JJ NNS",
"NN NNS",
"NNS NNS",
"NN NN",
"JJ NNS",
"JJ NN",
"NNP NN",
".*(NNS).+",
".*(NN).+"
".*IN (NN).*",
".*(NNP NNP NN).*",
".*(NNP NN NN).*",
".*(NNP NNS).*",
".*(NN JJ NNS).*",
".*(NN NNS).*",
".*(NNS NNS).*",
".*(NN NN).*",
".*(JJ NNS).*",
".*(JJ NN).*",
".*(NNP NN).*",
".*(NNS).*",
".*(NN).*"
]
}

{
VALUE: [
"CD CD",
"CD"
".*(CD CD).*",
".*(CD).*"
]
}
]
Expand Down
20 changes: 14 additions & 6 deletions stargraph-core/src/test/resources/dbpedia-2016-test-queries.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
{
"query": "What is the birth name of Angela Merkel?",
"accepted": [
"\"Angela Dorothea Kasner\"@en"
"\"Angela Dorothea Kasner\"@en",
"\"Angela Dorothea Kasner\"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>"
]
},
{
Expand Down Expand Up @@ -82,7 +83,8 @@
{
"query": "Who created Goofy?",
"accepted": [
"\"Walt Disney, Frank Webb\"@en"
"\"Walt Disney, Frank Webb\"@en",
"\"Walt Disney, Frank Webb\"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>"
]
},
{
Expand All @@ -94,7 +96,8 @@
{
"query": "What are the nicknames of San Francisco?",
"accepted": [
"\"The City by the Bay; Fog City; San Fran; Frisco ; The City that Knows How ; Baghdad by the Bay ; The Paris of the West\"@en"
"\"The City by the Bay; Fog City; San Fran; Frisco ; The City that Knows How ; Baghdad by the Bay ; The Paris of the West\"@en",
"\"The City by the Bay; Fog City; San Fran; Frisco ; The City that Knows How ; Baghdad by the Bay ; The Paris of the West\"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>"
]
},
{
Expand Down Expand Up @@ -260,7 +263,9 @@
{
"query": "Where is the source of the Amazon River?",
"accepted": [
"\"Andes\"@en"
"\"Andes\"@en",
"\"Andes\"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>",
"http://dbpedia.org/resource/Andes"
]
},
{
Expand Down Expand Up @@ -311,7 +316,9 @@
{
"query": "What is the capital of Bavaria?",
"accepted": [
"\"Munich\"@en"
"\"Munich\"@en",
"\"Munich\"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>",
"http://dbpedia.org/resource/Munich"
]
},
{
Expand Down Expand Up @@ -373,7 +380,8 @@
{
"query": "What is the latin name of Brodmann Area 44?",
"accepted": [
"\"Area opercularis\"@en"
"\"Area opercularis\"@en",
"\"Area opercularis\"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>"
]
},
{
Expand Down

0 comments on commit 425cb2f

Please sign in to comment.