コード例 #1
0
    /* @see com.hp.hpl.jena.sparql.syntax.ElementVisitorBase#visit(com.hp.hpl.jena.sparql.syntax.ElementTriplesBlock) */
    @Override
    public void visit(final ElementTriplesBlock elementtriplesblock) {
      for (final Triple t : elementtriplesblock.getPattern()) {
        try {
          if (t.getPredicate().isVariable())
            throw new IllegalArgumentException(
                "Variables cannot be used in predicate position in ABoxQuery");

          Atom atom = null;
          final String predURI = t.getPredicate().getURI();
          if (RDF.type.getURI().equals(predURI)) {
            if (t.getObject().isVariable())
              throw new IllegalArgumentException(
                  "Variables cannot be used as objects of rdf:type triples in ABoxQuery");

            final OWLClass c = owlModel.createClass(new URI(t.getObject().getURI()));
            final SWRLIndividualObject arg = makeIndividalObject(t.getSubject());

            atom = swrlFactory.createClassAtom(c, arg);
          } else {
            final OWLProperty p = owlModel.getProperty(new URI(predURI));

            if (p == null)
              throw new IllegalArgumentException(
                  predURI + " is unknown [Object|Datatype]Property in the backing OWL model.");
            else if (p.isDatatypeProperty()) {
              final OWLDataProperty dp = owlModel.createDataProperty(p.getURI());
              final SWRLIndividualObject arg1 = makeIndividalObject(t.getSubject());
              final SWRLDataObject arg2 = makeDataObject(t.getObject());

              atom = swrlFactory.createDataPropertyAtom(dp, arg1, arg2);
            } else if (p.isObjectProperty()) {
              final OWLObjectProperty op = owlModel.createObjectProperty(p.getURI());
              final SWRLIndividualObject arg1 = makeIndividalObject(t.getSubject());
              final SWRLIndividualObject arg2 = makeIndividalObject(t.getObject());

              atom = swrlFactory.createIndividualPropertyAtom(op, arg1, arg2);
            }
            // else it could be a annotation property, which are not relevant anyway
          }

          if (atom != null) atoms = atoms.cons(atom);
        } catch (final URISyntaxException e) {
          throw new IllegalArgumentException(
              e.getInput() + " appearing in the query string is not a valid URI!");
        }
      }
    }
コード例 #2
0
 private SWRLIndividualObject makeIndividalObject(final Node node) throws URISyntaxException {
   if (node.isVariable()) {
     final SWRLIndividualVariable var =
         swrlFactory.createIndividualVariable(new URI(varNS + node.getName()));
     vars.put(node.toString(), var);
     return var;
   }
   final OWLIndividual ind = owlModel.createIndividual(null, new URI(node.getURI()));
   return swrlFactory.wrapIndividual(ind);
 }
コード例 #3
0
 private SWRLDataObject makeDataObject(final Node node) throws URISyntaxException {
   if (node.isVariable()) {
     final SWRLDataVariable var =
         swrlFactory.createDataVariable(new URI(varNS + node.getName()));
     vars.put(node.toString(), var);
     return var;
   }
   final OWLDataValue value =
       new OWLDataValueImpl(new LiteralImpl(node, (EnhGraph) owlModel.getImplementation()));
   return swrlFactory.wrapDataValue(value);
 }
コード例 #4
0
    private SWRLDataObject makeDataObject(final Expr expr) throws URISyntaxException {
      if (expr.isVariable()) {
        return swrlFactory.createDataVariable(new URI(varNS + expr.getVarName()));
      } else if (expr.isConstant()) {
        final NodeValue nv = (NodeValue) expr;
        OWLDataValue value;
        if (nv.isInteger()) value = owlModel.createDataValue(nv.getInteger());
        else if (nv.isDouble()) value = owlModel.createDataValue(Double.valueOf(nv.getDouble()));
        else if (nv.isFloat()) value = owlModel.createDataValue(Float.valueOf(nv.getFloat()));
        else if (nv.isBoolean()) value = owlModel.createDataValue(Boolean.valueOf(nv.getBoolean()));
        else if (nv.isString()) value = owlModel.createDataValue(nv.getString());
        else if (nv.isDecimal()) value = owlModel.createDataValue(nv.getDecimal());
        else if (nv.hasDateTime()) value = owlModel.createDataValue(nv.getDateTime());
        else /* if (nv.isLiteral()) */ throw new NotImplementedException();

        return swrlFactory.wrapDataValue(value);
      } else {
        throw new IllegalArgumentException(
            "Nested constraint (filter) near " + expr + " can not be transformed to SWRL atom.");
      }
    }
コード例 #5
0
    private SWRLDataObject makeDataObject(final Expression expr) throws URISyntaxException {
      if (expr.isVariable()) {
        return swrlFactory.createDataVariable(new URI(varNS + expr.getName()));
      } else if (expr.isConstant()) {
        OWLDataValue value = null;
        if (expr instanceof ParsedLiteral) {
          final ParsedLiteral lit = (ParsedLiteral) expr;
          if (lit.isInt()) value = owlModel.createDataValue(Long.valueOf(lit.getInt()));
          else if (lit.isDouble())
            value = owlModel.createDataValue(Double.valueOf(lit.getDouble()));
          else if (lit.isBoolean())
            value = owlModel.createDataValue(Boolean.valueOf(lit.getBoolean()));
          else if (lit.isString()) value = owlModel.createDataValue(lit.getString());
          else if (lit.isURI()) value = owlModel.createDataValue(URI.create(lit.getURI()));
          else /* if (lit.isNode()) */ throw new NotImplementedException();
        } else value = owlModel.createDataValue(expr.getValue());

        return swrlFactory.wrapDataValue(value);
      } else {
        throw new IllegalArgumentException(
            "Nested constraint expressions near " + expr + " can not be transformed to SWRL atom.");
      }
    }
コード例 #6
0
 /* @see org.mindswap.owls.grounding.WSDLGroundingProvider#createWSDLOperationRef(java.net.URI, org.mindswap.owl.OWLModel) */
 public WSDLOperationRef createWSDLOperationRef(final URI uri, final OWLModel model) {
   return new WSDLOperationRefImpl(model.createInstance(OWLS.Grounding.WsdlOperationRef, uri));
 }
コード例 #7
0
 /* @see org.mindswap.owls.grounding.WSDLGroundingProvider#createWSDLOutputMessageMap(java.net.URI, org.mindswap.owl.OWLModel) */
 public MessageMap<String> createWSDLOutputMessageMap(final URI uri, final OWLModel model) {
   return new WSDLMessageMapImpl(model.createInstance(OWLS.Grounding.WsdlOutputMessageMap, uri));
 }
コード例 #8
0
 /* @see org.mindswap.owls.grounding.WSDLGroundingProvider#createWSDLGrounding(java.net.URI, org.mindswap.owl.OWLModel) */
 public WSDLGrounding createWSDLGrounding(final URI uri, final OWLModel model) {
   return new WSDLGroundingImpl(model.createInstance(OWLS.Grounding.WsdlGrounding, uri));
 }