Examples of LiteralLabel


Examples of com.hp.hpl.jena.graph.impl.LiteralLabel

        return f;
    }
   
    public static double nodeToDouble(Node node)
    {
        LiteralLabel lit = node.getLiteral();
       
        if ( ! XSDDatatype.XSDdouble.isValidLiteral(lit) )
            return Double.NaN;
        double d = ((Number)lit.getValue()).doubleValue();
        return d;
    }
View Full Code Here

Examples of com.hp.hpl.jena.graph.impl.LiteralLabel

     */
    public static boolean isTypeOK(Node val, Node dt) {
        if (!dt.isURI()) return false;
        if (val.isBlank()) return true;
        if (val.isLiteral()) {
            LiteralLabel ll = val.getLiteral();
            if (ll.getDatatype() != null && (! ll.isWellFormed())) return false;
            if (dt.equals(RDFS.Nodes.Literal)) {
                return true;
            } else {
                RDFDatatype dtype = TypeMapper.getInstance().getSafeTypeByName(dt.getURI());
                return dtype.isValidLiteral(val.getLiteral());  
View Full Code Here

Examples of com.hp.hpl.jena.graph.impl.LiteralLabel

     *
     * @return a new literal representing the value v
     */
    @Override
    public Literal createTypedLiteral(String v)  {
        LiteralLabel ll = LiteralLabelFactory.create(v);
        return new LiteralImpl(NodeFactory.createLiteral(ll), this);
    }
View Full Code Here

Examples of com.hp.hpl.jena.graph.impl.LiteralLabel

     * Create a typed literal xsd:dateTime from a Calendar object.
     */
    @Override
    public Literal createTypedLiteral(Calendar cal) {
        Object value = new XSDDateTime(cal);
        LiteralLabel ll = LiteralLabelFactory.create(value, "", XSDDatatype.XSDdateTime);
        return new LiteralImpl(NodeFactory.createLiteral(ll), this);

    }
View Full Code Here

Examples of com.hp.hpl.jena.graph.impl.LiteralLabel

     * @param value the value of the literal
     * @param dtype the type of the literal, null for old style "plain" literals
     */
    @Override
    public Literal createTypedLiteral(Object value, RDFDatatype dtype) {
        LiteralLabel ll = LiteralLabelFactory.create(value, "", dtype);
        return new LiteralImpl( NodeFactory.createLiteral(ll), this );
    }
View Full Code Here

Examples of com.hp.hpl.jena.graph.impl.LiteralLabel

     * @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.createLiteralLabel( lex, "", dt );
        return new LiteralImpl( NodeFactory.createLiteral(ll), this );
    }
View Full Code Here

Examples of com.hp.hpl.jena.graph.impl.LiteralLabel

     * @param typeURI the URI of the type of the literal, null for old style "plain" literals
     */
    @Override
    public Literal createTypedLiteral(Object value, String typeURI) {
        RDFDatatype dt = TypeMapper.getInstance().getSafeTypeByName(typeURI);
        LiteralLabel ll = LiteralLabelFactory.create(value, "", dt);
        return new LiteralImpl(NodeFactory.createLiteral(ll), this);
    }
View Full Code Here

Examples of com.hp.hpl.jena.graph.impl.LiteralLabel

    public Literal createTypedLiteral( Object value )
    {
        // Catch special case of a Calendar which we want to act as if it were an XSDDateTime
        if (value instanceof Calendar)
            return createTypedLiteral( (Calendar)value );
        LiteralLabel ll = LiteralLabelFactory.create( value );
        return new LiteralImpl( NodeFactory.createLiteral( ll ), this);
    }
View Full Code Here

Examples of com.hp.hpl.jena.graph.impl.LiteralLabel

            if (value.isBlank()) return null;
            if (!value.isLiteral()) {
                return new ValidityReport.Report(true, "dtRange",
                    "Property " + prop + " has a typed range but was given a non literal value " + value);
            }
            LiteralLabel ll = value.getLiteral();  
            for (Iterator<RDFDatatype> i = range.iterator(); i.hasNext(); ) {
                RDFDatatype dt = i.next();
                if (!dt.isValidLiteral(ll)) {
                    return new ValidityReport.Report(true, "dtRange",
                        "Property " + prop + " has a typed range " + dt +
View Full Code Here

Examples of com.hp.hpl.jena.graph.impl.LiteralLabel

        }
    }
    
    private static NodeId inline$(Node node)
    {
        LiteralLabel lit = node.getLiteral() ;
        // Decimal is a valid supertype of integer but we handle integers and decimals differently.
       
        if ( node.getLiteralDatatype().equals(XSDDatatype.XSDdecimal) )
        {
            // Check lexical form.
            if ( ! XSDDatatype.XSDdecimal.isValidLiteral(lit) )
                return null ;
           
            // Not lit.getValue() because that may be a narrower type e.g. Integer.
            // .trim is how Jena does it but it rather savage. spc, \n \r \t.
            // But at this point we know it's a valid literal so the excessive
            // chopping by .trim is safe.
            BigDecimal decimal = new BigDecimal(lit.getLexicalForm().trim()) ;
            // Does range checking.
            DecimalNode dn = DecimalNode.valueOf(decimal) ;
            // null is "does not fit"
            if ( dn != null )
                // setType
                return new NodeId(dn.pack()) ;
            else
                return null ;
        }
        else    // Not decimal.
        {
            if ( XSDDatatype.XSDinteger.isValidLiteral(lit) )
            {
                // Check length of lexical form to see if it's in range of a long.
                // Long.MAX_VALUE =  9223372036854775807
                // Long.MIN_VALUE = -9223372036854775808
                // 9,223,372,036,854,775,807 is 19 digits.
               
                if ( lit.getLexicalForm().length() > 19 )
                    return null ;

                try {
                    long v = ((Number)lit.getValue()).longValue() ;
                    v = IntegerNode.pack(v) ;
                    // Value -1 is "does not fit"
                    if ( v != -1 )
                        return new NodeId(v) ;
                    else
                        return null ;
                }
                // Out of range for the type, not a long etc etc.
                catch (Throwable ex) { return null ; }
            }
        }
       
        if ( XSDDatatype.XSDdateTime.isValidLiteral(lit) )
        {
            // Could use the Jena/XSDDateTime object here rather than reparse the lexical form.
            // But this works and it's close to a release ...
            long v = DateTimeNode.packDateTime(lit.getLexicalForm()) ;
            if ( v == -1 )
                return null ;
            v = setType(v, DATETIME) ;
            return new NodeId(v) ;
        }
       
        if ( XSDDatatype.XSDdate.isValidLiteral(lit) )
        {
            long v = DateTimeNode.packDate(lit.getLexicalForm()) ;
            if ( v == -1 )
                return null ;
            v = setType(v, DATE) ;
            return new NodeId(v) ;
        }
       
        if ( XSDDatatype.XSDboolean.isValidLiteral(lit) )
        {
            long v = 0 ;
            boolean b = ((Boolean)lit.getValue()).booleanValue() ;
            //return new NodeValueBoolean(b, node) ;
            v = setType(v, BOOLEAN) ;
            if ( b )
                v = v | 0x01 ;
            return new NodeId(v) ;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.