示例#1
0
 public SPhraseSpec getNLForTriple(Triple t) {
   SPhraseSpec p = nlgFactory.createClause();
   // process predicate then return subject is related to
   if (t.getPredicate().isVariable()) {
     if (t.getSubject().isVariable()) {
       p.setSubject(t.getSubject().toString());
     } else {
       p.setSubject(getNPPhrase(t.getSubject().toString(), false));
     }
     p.setVerb("be related via " + t.getPredicate().toString() + " to");
     if (t.getObject().isVariable()) {
       p.setObject(t.getObject().toString());
     } else {
       p.setObject(getNPPhrase(t.getObject().toString(), false));
     }
   } else {
     NLGElement subj;
     if (t.getSubject().isVariable()) {
       subj = nlgFactory.createWord(t.getSubject().toString(), LexicalCategory.NOUN);
     } else {
       subj =
           nlgFactory.createWord(
               uriConverter.convert(t.getSubject().toString()), LexicalCategory.NOUN);
     }
     //        subj.setFeature(Feature.POSSESSIVE, true);
     //        PhraseElement np = nlgFactory.createNounPhrase(subj,
     // getEnglishLabel(t.getPredicate().toString()));
     p.setSubject(
         realiser.realise(subj) + "\'s " + uriConverter.convert(t.getPredicate().toString()));
     p.setVerb("be");
     if (t.getObject().isVariable()) {
       p.setObject(t.getObject().toString());
     } else if (t.getObject().isLiteral()) {
       p.setObject(t.getObject().getLiteralLexicalForm());
     } else {
       p.setObject(getNPPhrase(t.getObject().toString(), false));
     }
   }
   p.setFeature(Feature.TENSE, Tense.PRESENT);
   return p;
 }
示例#2
0
 /**
  * Takes a DBPedia class and returns the correct label for it
  *
  * @param className Name of a class
  * @return Label
  */
 public NPPhraseSpec getNPPhrase(String className, boolean plural) {
   NPPhraseSpec object = null;
   if (className.equals(OWL.Thing.getURI())) {
     object = nlgFactory.createNounPhrase(GenericType.ENTITY.getNlr());
   } else if (className.equals(RDFS.Literal.getURI())) {
     object = nlgFactory.createNounPhrase(GenericType.VALUE.getNlr());
   } else if (className.equals(RDF.Property.getURI())) {
     object = nlgFactory.createNounPhrase(GenericType.RELATION.getNlr());
   } else if (className.equals(RDF.type.getURI())) {
     object = nlgFactory.createNounPhrase(GenericType.TYPE.getNlr());
   } else {
     String label = uriConverter.convert(className);
     if (label != null) {
       object = nlgFactory.createNounPhrase(label);
     } else {
       object = nlgFactory.createNounPhrase(GenericType.ENTITY.getNlr());
     }
   }
   object.setPlural(plural);
   return object;
 }