예제 #1
0
  public static TriplePath substitute(TriplePath triplePath, Binding binding) {
    if (triplePath.isTriple())
      return new TriplePath(Substitute.substitute(triplePath.asTriple(), binding));

    Node s = triplePath.getSubject();
    Node o = triplePath.getObject();
    Node s1 = substitute(s, binding);
    Node o1 = substitute(o, binding);

    TriplePath tp = triplePath;
    if (s1 != s || o1 != o) tp = new TriplePath(s1, triplePath.getPath(), o1);
    return tp;
  }
예제 #2
0
  public NLGElement getNLFromSingleClause(Element e) {
    if (e instanceof ElementPathBlock) {
      ElementPathBlock epb = (ElementPathBlock) e;
      List<Triple> triples = new ArrayList<Triple>();

      // get all triples. We assume that the depth of union is always 1
      for (TriplePath tp : epb.getPattern().getList()) {
        Triple t = tp.asTriple();
        triples.add(t);
      }
      return getNLForTripleList(triples, "and");
    } // if clause is union clause then we generate or statements
    else if (e instanceof ElementUnion) {
      CoordinatedPhraseElement cpe;
      // cast to union
      ElementUnion union = (ElementUnion) e;
      List<Triple> triples = new ArrayList<Triple>();

      // get all triples. We assume that the depth of union is always 1
      for (Element atom : union.getElements()) {
        ElementPathBlock epb = ((ElementPathBlock) (((ElementGroup) atom).getElements().get(0)));
        if (!epb.isEmpty()) {
          Triple t = epb.getPattern().get(0).asTriple();
          triples.add(t);
        }
      }
      return getNLForTripleList(triples, "or");
    } // if it's a filter
    else if (e instanceof ElementFilter) {
      SPhraseSpec p = nlgFactory.createClause();
      ElementFilter filter = (ElementFilter) e;
      Expr expr = filter.getExpr();
      return getNLFromSingleExpression(expr);
    }
    return null;
  }
예제 #3
0
 public static void addVarsFromTriplePath(Collection<Var> acc, TriplePath tpath) {
   addVar(acc, tpath.getSubject());
   addVar(acc, tpath.getObject());
 }