Permalink
Browse files

"And what, we don't like bugs?" (Jay, Men in Black)

  • Loading branch information...
christina
christina committed Apr 11, 2012
1 parent c30405f commit 04a4291eb45de592f0cad8b056ce9750f45f7733
@@ -525,7 +525,7 @@ private void aggregateTypeAndLabelInformation(String var) {
// collect the above SPhraseSpecs
for (SPhraseSpec s : sentences) {
- String sstring = realiser.realiseSentence(s);
+ String sstring = realiser.realise(s).toString();
if ((sstring.startsWith(var+"\'s type is ") || sstring.startsWith(var+"\' type is ")) && !sstring.startsWith(var+"\'s type is ?")) {
type = s; optionalMap.put(sstring,false);
}
@@ -537,7 +537,7 @@ else if (sstring.startsWith(var+"\'s name is ") || sstring.startsWith(var+"\' na
}
}
for (SPhraseSpec s : optionalsentences) {
- String sstring = realiser.realiseSentence(s);
+ String sstring = realiser.realise(s).toString();
if ((sstring.startsWith(var+"\'s type is ") || sstring.startsWith(var+"\' type is ")) && !sstring.startsWith(var+"\'s type is ?")) {
type = s; optionalMap.put(sstring,true);
}
@@ -561,26 +561,26 @@ else if (sstring.startsWith(var+"\'s name is ") || sstring.startsWith(var+"\' na
String noun = "";
boolean already = false;
if (label != null) {
- String sstring = realiser.realiseSentence(label);
+ String sstring = realiser.realise(label).toString();
String lang = checkLanguage(label.getObject().getFeatureAsString("head"));
if (lang != null) noun += lang + " ";
String pattern;
if (var.endsWith("s")) pattern = var+"\' label is ";
else pattern = var+"\'s label is ";
- noun += "label " + sstring.replace(pattern,"").replaceAll("\\.","");
+ noun += "label \"" + sstring.replace(pattern,"") + "\"";
already = true;
if (optionalMap.get(sstring)) { optionalsentences.remove(label); opt = true; }
else sentences.remove(label);
}
if (name != null) {
if (already) noun += " and ";
- String sstring = realiser.realiseSentence(name);
+ String sstring = realiser.realise(name).toString();
String lang = checkLanguage(name.getObject().getFeatureAsString("head"));
if (lang != null) noun += lang + " ";
String pattern;
if (var.endsWith("s")) pattern = var+"\' name is ";
else pattern = var+"\'s name is ";
- noun += "name " + sstring.replace(pattern,"").replaceAll("\\.","");
+ noun += "name \"" + sstring.replace(pattern,"") + "\"";
if (optionalMap.get(sstring)) { optionalsentences.remove(name); opt = true; }
else sentences.remove(name);
already = true;
@@ -591,21 +591,21 @@ else if (sstring.startsWith(var+"\'s name is ") || sstring.startsWith(var+"\' na
}
if (type != null) {
- String sstring = realiser.realiseSentence(type);
+ String sstring = realiser.realise(type).toString();
String pattern;
if (var.endsWith("s")) pattern = var+"\' type is ";
else pattern = var+"\'s type is ";
- String classstring = sstring.replace(pattern,"").replaceAll("\\.","");
+ String classstring = sstring.replace(pattern,"");
String determiner;
if (Pattern.matches("[a,i,e,u,o,A,I,E,U,O].*",classstring)) determiner = "an";
else determiner = "a";
objnp = nlg.createNounPhrase(determiner,classstring);
- if (np != null) objnp.addPostModifier(("with " + realiser.realise(np)).replaceAll("\\.",""));
+ if (np != null) objnp.addPostModifier(("with " + realiser.realise(np).toString()));
newsentence.setVerb("be");
newsentence.setObject(objnp);
// removal:
if (optionalMap.get(sstring)) { optionalsentences.remove(type); opt = true; }
- else sentences.remove(type);
+ else sentences.remove(type);
}
else {
newsentence.setVerb("have");
@@ -702,7 +702,7 @@ else if (fstring.startsWith(var + " does not exist")) {
newhead = "";
}
else {
- newhead = "no "+obj;
+ // newhead = "no "+obj; // TODO change this!
}
}
else sentence.setFeature("negated",true);
@@ -783,12 +783,17 @@ else if (oc == 1) {
for (SPhraseSpec s : sentences) {
// selects TYPE ?x such that ?x is OBJECT -> selects OBJECT
if (((WordElement) s.getVerb()).getBaseForm().equals("be")) {
- if (realiser.realise(s.getSubject()).toString().equals("?"+var)) {
- replacements.put(sel,nlg.createNounPhrase(s.getObject()));
- delete.add(s); break;
- }
- else if (realiser.realise(s.getObject()).toString().equals("?"+var)) {
- replacements.put(sel,nlg.createNounPhrase(s.getSubject()));
+ NPPhraseSpec repl = null;
+ if (realiser.realise(s.getSubject()).toString().equals("?"+var))
+ repl = nlg.createNounPhrase(s.getObject());
+ else if (realiser.realise(s.getObject()).toString().equals("?"+var))
+ repl = nlg.createNounPhrase(s.getSubject());
+ if (repl != null) {
+ if (realiser.realise(sel).toString().contains(" number of ")) {
+ repl.setPlural(true); // .setFeature(Feature.NUMBER,NumberAgreement.PLURAL);
+ repl.addPreModifier("the number of ");
+ }
+ replacements.put(sel,repl);
delete.add(s); break;
}
}
@@ -863,8 +868,9 @@ private void fuseWithSelectsAgain(Set<NLGElement> bodyparts) {
NLGElement bodypart = null;
if (bodyparts.size() == 1) {
NLGElement bp = new ArrayList<NLGElement>(bodyparts).get(0);
- String b = realiser.realiseSentence(bp);
+ String b = realiser.realise(bp).toString();
if (!b.contains(" and ") && !b.contains(" or ") && !b.contains(" not ")) {
+ // Case 1: is-sentence
Pattern p = Pattern.compile("(\\?[\\w]*) is (.*)\\.");
Matcher m = p.matcher(b);
if (m.matches()) {
@@ -875,6 +881,9 @@ private void fuseWithSelectsAgain(Set<NLGElement> bodyparts) {
oldspec = sel;
newspec = nlg.createNounPhrase();
newspec.setFeature("head",m.group(2));
+ if (realiser.realise(oldspec).toString().contains(" number of ")) {
+ newspec.addPreModifier("the number of");
+ }
if (oldspec.hasFeature("postmodifiers")) {
newspec.addPostModifier(oldspec.getFeatureAsStringList("postmodifiers").get(0).replace("their","its"));
}
@@ -884,9 +893,51 @@ private void fuseWithSelectsAgain(Set<NLGElement> bodyparts) {
selects.add(newspec);
bodypart = bp;
}
+ // Case 2: some other verb
+ p = Pattern.compile("(\\?[\\w]*) (.*)\\.");
+ m = p.matcher(b);
+ if (m.matches()) {
+ NPPhraseSpec oldspec = null;
+ NPPhraseSpec newspec = null;
+ for (NPPhraseSpec sel : selects) {
+ if (sel.getFeatureAsString("head").equals(m.group(1))) {
+ oldspec = sel;
+ newspec = nlg.createNounPhrase();
+ newspec.setFeature("head",realiser.realise(sel).toString().replace(m.group(1),""));
+ boolean oldPlural = bp.isPlural();
+ bp.setPlural(true);
+ newspec.addComplement("that" + realiser.realise(bp).toString().replace(m.group(1),""));
+ bp.setPlural(oldPlural);
+ }
+ }
+ selects.remove(oldspec);
+ selects.add(newspec);
+ bodypart = bp;
+ }
}
}
if (bodypart != null) bodyparts.remove(bodypart);
+
+ // ?var and ?var's title -> ?var and their title
+ Pattern p = Pattern.compile("(\\?\\w*)\'s ((((t|T)itle)|((n|N)ame))(\\z|.*))");
+ Set<NPPhraseSpec> oldspecs = new HashSet<NPPhraseSpec>();
+ Set<NPPhraseSpec> newspecs = new HashSet<NPPhraseSpec>();
+ for (NPPhraseSpec select : selects) {
+ Matcher m = p.matcher(realiser.realise(select).toString());
+ if (m.matches()) {
+ for (NPPhraseSpec sel : selects) {
+ if (sel.getFeatureAsString("head").equals(m.group(1))) {
+ oldspecs.add(sel);
+ oldspecs.add(select);
+ NPPhraseSpec newspec = nlg.createNounPhrase(realiser.realise(sel).toString());
+ newspec.addPostModifier("and their " + m.group(2));
+ newspecs.add(newspec);
+ }
+ }
+ }
+ }
+ selects.removeAll(oldspecs);
+ selects.addAll(newspecs);
}
public NLGElement returnSelect() {
@@ -210,22 +210,17 @@ public static void main(String[] args) {
+ "SELECT DISTINCT ?date WHERE"
+ "{ res:Charmed dbo:starring ?actor ."
+ " ?actor dbo:birthDate ?date }";
- String query16 = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"
- + "PREFIX foaf: <http://xmlns.com/foaf/0.1/>"
+ String query16 = "PREFIX res: <http://dbpedia.org/resource/>"
+ "PREFIX dbo: <http://dbpedia.org/ontology/>"
- + "PREFIX dbp: <http://dbpedia.org/property/>"
- + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>"
- + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
- + "SELECT DISTINCT ?string WHERE "
- + "{ ?subject rdf:type dbo:Company ."
- + "?subject dbp:numEmployees ?employees ."
- + "FILTER ( ?employees = 100000 )."
- + "?subject foaf:homepage ?string ."
- + " FILTER (?subject = ?string) }";
-
+ + "ASK WHERE { OPTIONAL { res:Frank_Herbert dbo:deathDate ?date } FILTER ( ! bound(?date) ) }";
+ String query17 = "PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX mo: <http://purl.org/ontology/mo/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
+ + "SELECT DISTINCT ?album ?title WHERE"
+ + "{ ?album foaf:maker ?artist . ?artist foaf:name \"Slayer\" . ?album mo:release_type mo:single . ?album dc:title ?title }";
+ String query18 = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX bio: <http://purl.org/vocab/bio/0.1/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
+ + "SELECT DISTINCT ?artist ?artistname WHERE { ?artist foaf:name ?artistname . ?artist bio:event ?event . ?event rdf:type bio:Birth . ?event bio:date \"1962-05-30\"^^xsd:dateTime .}";
// String[] queries = {query,query2,query2b,query2c,query3,query3b,query4,query5,query6,query7,query8,query9,query10,query11,query14};
- String[] queries = {query16};
+ String[] queries = {query16,query18};
try {
SparqlEndpoint ep = new SparqlEndpoint(new URL("http://greententacle.techfak.uni-bielefeld.de:5171/sparql"));
Lexicon lexicon = Lexicon.getDefaultLexicon();

0 comments on commit 04a4291

Please sign in to comment.