Search in sources :

Example 51 with Node

use of org.apache.jena.graph.Node in project jena by apache.

the class CanonicalizeLiteral method apply.

@Override
public Node apply(Node node) {
    if (!node.isLiteral())
        return node;
    if (!node.getLiteralDatatype().isValid(node.getLiteralLexicalForm()))
        // Invalid lexical form for the datatype - do nothing.
        return node;
    RDFDatatype dt = node.getLiteralDatatype();
    Node n2;
    if (NodeUtils.isLangString(node)) {
        // RDF 1.0, no datatype ; RDF 1.1 : datatype is rdf:langString 
        if (node.getLiteralLanguage().equals(""))
            //n2 = NormalizeValue.dtSimpleLiteral.handle(node, node.getLiteralLexicalForm(), null) ;
            return node;
        else
            n2 = canonicalLangtag(node.getLiteralLexicalForm(), node.getLiteralLanguage());
    } else if (dt == null) {
        // RDF 1.0 / no lang.
        n2 = NormalizeValue.dtSimpleLiteral.handle(node, node.getLiteralLexicalForm(), null);
    } else {
        // Dataype, not rdf:langString (RDF 1.1). 
        DatatypeHandler handler = dispatch.get(dt);
        if (handler == null)
            return node;
        n2 = handler.handle(node, node.getLiteralLexicalForm(), dt);
    }
    if (n2 == null)
        return node;
    return n2;
}
Also used : Node(org.apache.jena.graph.Node) RDFDatatype(org.apache.jena.datatypes.RDFDatatype)

Example 52 with Node

use of org.apache.jena.graph.Node in project jena by apache.

the class RiotLib method createIRIorBNode.

/** Implement <_:....> as a "Node IRI"
     * that is, use the given label as the BNode internal label.
     * Use with care.
     */
public static Node createIRIorBNode(String iri) {
    // Is it a bNode label? i.e. <_:xyz>
    if (isBNodeIRI(iri)) {
        String s = iri.substring(bNodeLabelStart.length());
        Node n = NodeFactory.createBlankNode(s);
        return n;
    }
    return NodeFactory.createURI(iri);
}
Also used : LabelToNode(org.apache.jena.riot.lang.LabelToNode) Node(org.apache.jena.graph.Node)

Example 53 with Node

use of org.apache.jena.graph.Node in project jena by apache.

the class STriple method readObject.

private void readObject(java.io.ObjectInputStream in) throws IOException {
    TProtocol protocol = TRDF.protocol(in);
    RDF_Term tterm = new RDF_Term();
    Node s = SerializerRDF.read(protocol, tterm);
    Node p = SerializerRDF.read(protocol, tterm);
    Node o = SerializerRDF.read(protocol, tterm);
    triple = Triple.create(s, p, o);
}
Also used : TProtocol(org.apache.thrift.protocol.TProtocol) Node(org.apache.jena.graph.Node) RDF_Term(org.apache.jena.riot.thrift.wire.RDF_Term)

Example 54 with Node

use of org.apache.jena.graph.Node in project jena by apache.

the class SinkTripleOutput method send.

@Override
public void send(Triple triple) {
    Node s = triple.getSubject();
    Node p = triple.getPredicate();
    Node o = triple.getObject();
    nodeFmt.format(out, s);
    out.print(" ");
    nodeFmt.format(out, p);
    out.print(" ");
    nodeFmt.format(out, o);
    out.print(" .\n");
}
Also used : Node(org.apache.jena.graph.Node)

Example 55 with Node

use of org.apache.jena.graph.Node in project jena by apache.

the class RiotLib method calcWidth.

public static int calcWidth(PrefixMap prefixMap, String baseURI, Collection<Node> nodes, int minWidth, int maxWidth) {
    Node prev = null;
    int nodeMaxWidth = minWidth;
    for (Node n : nodes) {
        if (prev != null && prev.equals(n))
            continue;
        int len = calcWidth(prefixMap, baseURI, n);
        if (len > maxWidth)
            continue;
        if (nodeMaxWidth < len)
            nodeMaxWidth = len;
        prev = n;
    }
    return nodeMaxWidth;
}
Also used : LabelToNode(org.apache.jena.riot.lang.LabelToNode) Node(org.apache.jena.graph.Node)

Aggregations

Node (org.apache.jena.graph.Node)681 Test (org.junit.Test)191 Triple (org.apache.jena.graph.Triple)98 BaseTest (org.apache.jena.atlas.junit.BaseTest)85 Var (org.apache.jena.sparql.core.Var)84 ArrayList (java.util.ArrayList)55 Graph (org.apache.jena.graph.Graph)46 Binding (org.apache.jena.sparql.engine.binding.Binding)40 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)36 Quad (org.apache.jena.sparql.core.Quad)35 LabelToNode (org.apache.jena.riot.lang.LabelToNode)28 RDFNode (org.apache.jena.rdf.model.RDFNode)25 HashMap (java.util.HashMap)22 Model (org.apache.jena.rdf.model.Model)18 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)18 NodeId (org.apache.jena.tdb.store.NodeId)18 NodeWritable (org.apache.jena.hadoop.rdf.types.NodeWritable)16 Token (org.apache.jena.riot.tokens.Token)16 BasicPattern (org.apache.jena.sparql.core.BasicPattern)16 NodeValue (org.apache.jena.sparql.expr.NodeValue)16