Search in sources :

Example 26 with Node

use of com.hp.hpl.jena.graph.Node in project stanbol by apache.

the class IsBlankAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.IsBlankAtom tmp = (org.apache.stanbol.rules.manager.atoms.IsBlankAtom) ruleAtom;
    IObjectAtom uriResource = tmp.getUriResource();
    ClauseEntry argumentClauseEntry = adapter.adaptTo(uriResource, Rule.class);
    Node argNode;
    if (argumentClauseEntry instanceof NodeClauseEntry) {
        argNode = ((NodeClauseEntry) argumentClauseEntry).getNode();
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    java.util.List<Node> nodes = new ArrayList<Node>();
    nodes.add(argNode);
    return (T) new Functor("isBlankNode", nodes, BuiltinRegistry.theRegistry);
}
Also used : Node(com.hp.hpl.jena.graph.Node) ArrayList(java.util.ArrayList) Functor(com.hp.hpl.jena.reasoner.rulesys.Functor) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) ClauseEntry(com.hp.hpl.jena.reasoner.rulesys.ClauseEntry) NodeClauseEntry(org.apache.stanbol.rules.adapters.jena.NodeClauseEntry) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) NodeClauseEntry(org.apache.stanbol.rules.adapters.jena.NodeClauseEntry)

Example 27 with Node

use of com.hp.hpl.jena.graph.Node in project stanbol by apache.

the class ConcatAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    String concat_result = "concat_result" + System.currentTimeMillis();
    Node arg1Node = null;
    Node arg2Node = null;
    Node resultNode = Node_RuleVariable.createVariable(concat_result);
    ;
    org.apache.stanbol.rules.manager.atoms.ConcatAtom tmp = (org.apache.stanbol.rules.manager.atoms.ConcatAtom) ruleAtom;
    ExpressionAtom argument1 = tmp.getArgument1();
    ExpressionAtom argument2 = tmp.getArgument2();
    ClauseEntry clauseEntry1 = adapter.adaptTo(argument1, Rule.class);
    ClauseEntry clauseEntry2 = adapter.adaptTo(argument2, Rule.class);
    List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
    if (clauseEntry1 instanceof HigherOrderClauseEntry) {
        arg1Node = ((HigherOrderClauseEntry) clauseEntry1).getBindableNode();
        clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry1).getClauseEntries());
    } else if (clauseEntry1 instanceof NodeClauseEntry) {
        arg1Node = ((NodeClauseEntry) clauseEntry1).getNode();
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
    if (clauseEntry2 instanceof HigherOrderClauseEntry) {
        arg2Node = ((HigherOrderClauseEntry) clauseEntry2).getBindableNode();
        clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry2).getClauseEntries());
    } else if (clauseEntry2 instanceof NodeClauseEntry) {
        arg2Node = ((NodeClauseEntry) clauseEntry2).getNode();
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
    java.util.List<Node> nodes = new ArrayList<Node>();
    nodes.add(arg1Node);
    nodes.add(arg2Node);
    nodes.add(resultNode);
    return (T) new Functor("strConcat", nodes, new BuiltinRegistry());
}
Also used : Node(com.hp.hpl.jena.graph.Node) ArrayList(java.util.ArrayList) Functor(com.hp.hpl.jena.reasoner.rulesys.Functor) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom) HigherOrderClauseEntry(org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry) ClauseEntry(com.hp.hpl.jena.reasoner.rulesys.ClauseEntry) NodeClauseEntry(org.apache.stanbol.rules.adapters.jena.NodeClauseEntry) HigherOrderClauseEntry(org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry) NodeClauseEntry(org.apache.stanbol.rules.adapters.jena.NodeClauseEntry) BuiltinRegistry(com.hp.hpl.jena.reasoner.rulesys.BuiltinRegistry)

Example 28 with Node

use of com.hp.hpl.jena.graph.Node in project stanbol by apache.

the class DifferentAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    Node arg1Node = null;
    Node arg2Node = null;
    org.apache.stanbol.rules.manager.atoms.DifferentAtom tmp = (org.apache.stanbol.rules.manager.atoms.DifferentAtom) ruleAtom;
    ExpressionAtom argument1 = tmp.getStringFunctionAtom1();
    ExpressionAtom argument2 = tmp.getStringFunctionAtom2();
    ClauseEntry clauseEntry1 = adapter.adaptTo(argument1, Rule.class);
    ClauseEntry clauseEntry2 = adapter.adaptTo(argument2, Rule.class);
    List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
    if (clauseEntry1 instanceof HigherOrderClauseEntry) {
        arg1Node = ((HigherOrderClauseEntry) clauseEntry1).getBindableNode();
        clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry1).getClauseEntries());
    } else if (clauseEntry1 instanceof NodeClauseEntry) {
        arg1Node = ((NodeClauseEntry) clauseEntry1).getNode();
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
    if (clauseEntry2 instanceof HigherOrderClauseEntry) {
        arg2Node = ((HigherOrderClauseEntry) clauseEntry2).getBindableNode();
        clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry2).getClauseEntries());
    } else if (clauseEntry2 instanceof NodeClauseEntry) {
        arg2Node = ((NodeClauseEntry) clauseEntry2).getNode();
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
    java.util.List<Node> nodes = new ArrayList<Node>();
    nodes.add(arg1Node);
    nodes.add(arg2Node);
    return (T) new Functor("notEqual", nodes, BuiltinRegistry.theRegistry);
}
Also used : Node(com.hp.hpl.jena.graph.Node) ArrayList(java.util.ArrayList) Functor(com.hp.hpl.jena.reasoner.rulesys.Functor) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom) HigherOrderClauseEntry(org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry) ClauseEntry(com.hp.hpl.jena.reasoner.rulesys.ClauseEntry) NodeClauseEntry(org.apache.stanbol.rules.adapters.jena.NodeClauseEntry) HigherOrderClauseEntry(org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry) NodeClauseEntry(org.apache.stanbol.rules.adapters.jena.NodeClauseEntry)

Example 29 with Node

use of com.hp.hpl.jena.graph.Node in project stanbol by apache.

the class RdfIndexingSource method getEntityData.

@Override
public Representation getEntityData(String id) {
    final Node resource;
    //STANBOL-765: check if the parsed id represents an bnode
    if (bnodePrefix != null && id.startsWith(bnodePrefix)) {
        resource = NodeFactory.createAnon(AnonId.create(id.substring(bnodePrefix.length())));
    } else {
        resource = NodeFactory.createURI(id);
    }
    Representation source = vf.createRepresentation(id);
    boolean found;
    ExtendedIterator<Triple> outgoing = null;
    try {
        // There may still be exceptions while reading triples
        outgoing = indexingDataset.getDefaultGraph().find(resource, null, null);
        found = outgoing.hasNext();
        while (outgoing.hasNext()) {
            //iterate over the statements for that resource
            Triple statement = outgoing.next();
            Node predicate = statement.getPredicate();
            if (predicate == null || !predicate.isURI()) {
                log.warn("Ignore field {} for resource {} because it is null or not an URI!", predicate, resource);
            } else {
                String field = predicate.getURI();
                Node value = statement.getObject();
                processValue(value, source, field);
            }
        //end else predicate != null
        }
    //end iteration over resource triple
    } catch (Exception e) {
        log.warn("Unable to retrieve entity data for Entity '" + id + "'", e);
        found = false;
        try {
            if (outgoing != null) {
                outgoing.close();
            }
        } catch (Exception e1) {
        /* ignore */
        }
    }
    if (found) {
        if (log.isTraceEnabled()) {
            log.info("RDFTerm: \n{}", ModelUtils.getRepresentationInfo(source));
        }
        return source;
    } else {
        log.debug("No Statements found for id {} (Node: {})!", id, resource);
        return null;
    }
}
Also used : Triple(com.hp.hpl.jena.graph.Triple) Node(com.hp.hpl.jena.graph.Node) RDFNode(com.hp.hpl.jena.rdf.model.RDFNode) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) URISyntaxException(java.net.URISyntaxException) NoSuchElementException(java.util.NoSuchElementException) DatatypeFormatException(com.hp.hpl.jena.datatypes.DatatypeFormatException)

Example 30 with Node

use of com.hp.hpl.jena.graph.Node in project stanbol by apache.

the class RdfIndexingSource method listSubjects.

@Override
public Collection<Node> listSubjects(Node property, Node object) {
    Collection<Node> nodes = new ArrayList<Node>();
    if (bnodePrefix != null && object.isURI() && object.getURI().startsWith(bnodePrefix)) {
        object = NodeFactory.createAnon(new AnonId(object.getURI().substring(bnodePrefix.length())));
    }
    ExtendedIterator<Triple> it = indexingDataset.getDefaultGraph().find(null, property, object);
    while (it.hasNext()) {
        Node subject = it.next().getSubject();
        //RDFBackend implementation
        if (bnodePrefix != null && subject.isBlank()) {
            StringBuilder sb = new StringBuilder(bnodePrefix);
            sb.append(subject.getBlankNodeId().getLabelString());
            subject = NodeFactory.createURI(sb.toString());
        }
        nodes.add(subject);
    }
    it.close();
    return nodes;
}
Also used : Triple(com.hp.hpl.jena.graph.Triple) Node(com.hp.hpl.jena.graph.Node) RDFNode(com.hp.hpl.jena.rdf.model.RDFNode) ArrayList(java.util.ArrayList) AnonId(com.hp.hpl.jena.rdf.model.AnonId)

Aggregations

Node (com.hp.hpl.jena.graph.Node)31 NodeClauseEntry (org.apache.stanbol.rules.adapters.jena.NodeClauseEntry)23 ClauseEntry (com.hp.hpl.jena.reasoner.rulesys.ClauseEntry)20 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)20 ArrayList (java.util.ArrayList)18 Functor (com.hp.hpl.jena.reasoner.rulesys.Functor)16 HigherOrderClauseEntry (org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry)15 ExpressionAtom (org.apache.stanbol.rules.manager.atoms.ExpressionAtom)9 IObjectAtom (org.apache.stanbol.rules.manager.atoms.IObjectAtom)7 TriplePattern (com.hp.hpl.jena.reasoner.TriplePattern)4 NumericFunctionAtom (org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom)4 Triple (com.hp.hpl.jena.graph.Triple)3 RDFNode (com.hp.hpl.jena.rdf.model.RDFNode)3 BuiltinRegistry (com.hp.hpl.jena.reasoner.rulesys.BuiltinRegistry)3 LiteralLabel (com.hp.hpl.jena.graph.impl.LiteralLabel)2 AnonId (com.hp.hpl.jena.rdf.model.AnonId)2 URIResource (org.apache.stanbol.rules.base.api.URIResource)2 DatatypeFormatException (com.hp.hpl.jena.datatypes.DatatypeFormatException)1 Builtin (com.hp.hpl.jena.reasoner.rulesys.Builtin)1 Binding (com.hp.hpl.jena.sparql.engine.binding.Binding)1