Search in sources :

Example 21 with RDFDatatype

use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.

the class FBRuleInfGraph method getDTRange.

/**
     * Return a map from property nodes to a list of RDFDatatype objects
     * which have been declared as the range of that property.
     */
protected HashMap<Node, List<RDFDatatype>> getDTRange() {
    if (dtRange == null) {
        dtRange = new HashMap<>();
        for (Iterator<Triple> i = find(null, RDFS.range.asNode(), null); i.hasNext(); ) {
            Triple triple = i.next();
            Node prop = triple.getSubject();
            Node rangeValue = triple.getObject();
            if (rangeValue.isURI()) {
                RDFDatatype dt = TypeMapper.getInstance().getTypeByName(rangeValue.getURI());
                if (dt != null) {
                    List<RDFDatatype> range = dtRange.get(prop);
                    if (range == null) {
                        range = new ArrayList<>();
                        dtRange.put(prop, range);
                    }
                    range.add(dt);
                }
            }
        }
    }
    return dtRange;
}
Also used : RDFNode(org.apache.jena.rdf.model.RDFNode) RDFDatatype(org.apache.jena.datatypes.RDFDatatype)

Example 22 with RDFDatatype

use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.

the class Util method isSimpleString.

/**
     * A Node is a simple string if: 
     * <li>(RDF 1.0) No datatype and no language tag.
     * <li>(RDF 1.1) xsd:string
     */
public static boolean isSimpleString(Node n) {
    Objects.requireNonNull(n);
    RDFDatatype dt = n.getLiteralDatatype();
    if (dt == null)
        return !isLangString(n);
    if (JenaRuntime.isRDF11)
        return dt.equals(XSDDatatype.XSDstring);
    return false;
}
Also used : RDFDatatype(org.apache.jena.datatypes.RDFDatatype)

Example 23 with RDFDatatype

use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.

the class ModelCom method createTypedLiteral.

/**
     * Build a typed literal from its lexical form. The
     * lexical form will be parsed now and the value stored. If
     * the form is not legal this will throw an exception.
     * 
     * @param lex the lexical form of the literal
     * @param typeURI the uri of the type of the literal, null for old style "plain" literals
     * @throws DatatypeFormatException if lex is not a legal form of dtype
     */
@Override
public Literal createTypedLiteral(String lex, String typeURI) {
    RDFDatatype dt = TypeMapper.getInstance().getSafeTypeByName(typeURI);
    LiteralLabel ll = LiteralLabelFactory.create(lex, dt);
    return new LiteralImpl(NodeFactory.createLiteral(ll), this);
}
Also used : RDFDatatype(org.apache.jena.datatypes.RDFDatatype) LiteralLabel(org.apache.jena.graph.impl.LiteralLabel)

Example 24 with RDFDatatype

use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.

the class ParserBase method createLiteral.

protected Node createLiteral(String lexicalForm, String langTag, String datatypeURI) {
    Node n = null;
    // Can't have type and lang tag.
    if (datatypeURI != null) {
        RDFDatatype dType = TypeMapper.getInstance().getSafeTypeByName(datatypeURI);
        n = NodeFactory.createLiteral(lexicalForm, null, dType);
    } else
        n = NodeFactory.createLiteral(lexicalForm, langTag, null);
    return n;
}
Also used : Node(org.apache.jena.graph.Node) RDFDatatype(org.apache.jena.datatypes.RDFDatatype)

Example 25 with RDFDatatype

use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.

the class ParserBase method createLiteral.

protected Node createLiteral(String lexicalForm, String langTag, String datatypeURI) {
    Node n = null;
    // Can't have type and lang tag in parsing.
    if (datatypeURI != null) {
        RDFDatatype dType = TypeMapper.getInstance().getSafeTypeByName(datatypeURI);
        n = NodeFactory.createLiteral(lexicalForm, dType);
    } else if (langTag != null && !langTag.isEmpty())
        n = NodeFactory.createLiteral(lexicalForm, langTag);
    else
        n = NodeFactory.createLiteral(lexicalForm);
    return n;
}
Also used : Node(org.apache.jena.graph.Node) RDFDatatype(org.apache.jena.datatypes.RDFDatatype)

Aggregations

RDFDatatype (org.apache.jena.datatypes.RDFDatatype)35 Node (org.apache.jena.graph.Node)9 LiteralLabel (org.apache.jena.graph.impl.LiteralLabel)6 TypeMapper (org.apache.jena.datatypes.TypeMapper)4 RDFLangString (org.apache.jena.datatypes.xsd.impl.RDFLangString)4 BigDecimal (java.math.BigDecimal)3 BigInteger (java.math.BigInteger)2 DatatypeFormatException (org.apache.jena.datatypes.DatatypeFormatException)2 RDFNode (org.apache.jena.rdf.model.RDFNode)2 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)2 FileReader (java.io.FileReader)1 Duration (javax.xml.datatype.Duration)1 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)1 BaseDatatype (org.apache.jena.datatypes.BaseDatatype)1 XSDDateTime (org.apache.jena.datatypes.xsd.XSDDateTime)1 EnhNode (org.apache.jena.enhanced.EnhNode)1 RiotException (org.apache.jena.riot.RiotException)1 LabelToNode (org.apache.jena.riot.lang.LabelToNode)1 Token (org.apache.jena.riot.tokens.Token)1 Item (org.apache.jena.sparql.sse.Item)1