コード例 #1
0
  /* @see org.mindswap.common.Parser#parse(java.lang.Object) */
  public ABoxQuery<Variable> parse(final String queryString) throws ParseException {
    if (queryString == null) throw new ParseException(queryString, "Query string null.");

    final Query query;
    try {
      switch (lang) {
        case RDQL:
          query = QueryFactory.create(queryString, Syntax.syntaxRDQL);
          break;
        case SPARQL_DL:
        case SPARQL:
        default:
          query = QueryFactory.create(queryString, Syntax.syntaxSPARQL);
          break;
      }
    } catch (final QueryException e) {
      throw new ParseException(queryString, e);
    }

    final ISWRLFactory swrlFactory = SWRLFactory.createFactory(model);
    final Map<String, Variable> vars = new HashMap<String, Variable>();
    final Element elmnt = query.getQueryPattern();
    final ElementVisitor v = new ElementVisitor(model, swrlFactory, vars);
    elmnt.visit(v);
    final OWLList<Atom> atomList = v.getAtomList();

    final List<Variable> resultVars = new ArrayList<Variable>();
    for (final String var : query.getResultVars()) {
      resultVars.add(vars.get("?" + var));
    }

    return new ABoxQuery<Variable>(atomList, resultVars);
  }
コード例 #2
0
ファイル: SimpleNLG.java プロジェクト: QTL2/SemWeb2NL
 private Set<String> getVars(List<Element> elements, Set<String> projectionVars) {
   Set<String> result = new HashSet<String>();
   for (Element e : elements) {
     for (String var : projectionVars) {
       if (e.toString().contains("?" + var)) {
         result.add(var);
       }
     }
   }
   return result;
 }
コード例 #3
0
 /* @see com.hp.hpl.jena.sparql.syntax.ElementVisitorBase#visit(com.hp.hpl.jena.sparql.syntax.ElementGroup) */
 @Override
 public void visit(final ElementGroup elementgroup) {
   for (final Element e : elementgroup.getElements()) {
     e.visit(this);
   }
 }