Package com.hp.hpl.jena.datatypes

Examples of com.hp.hpl.jena.datatypes.TypeMapper


    Node s = env.getGroundVersion(args[0]);
    Node p = env.getGroundVersion(args[1]);
    ExtendedIterator i = graph.find(s,p,null);
    int n = i.toSet().size();
   
    TypeMapper tm = TypeMapper.getInstance();
    RDFDatatype type = tm.getTypeByName(XSD.xint.getURI());
    Node count = Node.createLiteral(Integer.toString(n),null,type);
    env.bind(args[2],count);
    return true;
  }
View Full Code Here


   * @see com.hp.hpl.jena.reasoner.rulesys.Builtin#bodyCall(com.hp.hpl.jena.graph.Node[], int, com.hp.hpl.jena.reasoner.rulesys.RuleContext)
   */
  public boolean bodyCall(Node[] args, int length, RuleContext context) {
    BindingEnvironment env = context.getEnv();
    Node value = env.getGroundVersion(args[0]);
    TypeMapper tm = TypeMapper.getInstance();
    RDFDatatype type = tm.getTypeByName(PrintUtil.expandQname(args[2].toString()));
    Node cast = Node.createLiteral(value.getLiteral().getValue().toString(),null,type);
    env.bind(args[1],cast);
    return type.isValid(value.getLiteral().getValue().toString());
  }
View Full Code Here

   * @param type
   * @return
   */
  protected static RDFDatatype getDatatype(String type) {
    if (type==null) return null;
    TypeMapper tm = TypeMapper.getInstance();
    RDFDatatype dt = tm.getTypeByName(type);
    if (dt == null) {
      // we've got a new (derived) datatype here
      dt = new BaseDatatype(type);
      tm.registerDatatype(dt);
    }
    return dt;
  }
View Full Code Here

        assertFalse( "", Node.ANY.matches( null ) );
        }
       
    public void testDataMatches()
        {
        TypeMapper tm = TypeMapper.getInstance();
        RDFDatatype dt1 = tm.getTypeByValue( new Integer( 10 ) );
        RDFDatatype dt2 = tm.getTypeByValue( new Short( (short) 10 ) );
        Node a = Node.createLiteral( "10", "", dt1 );
        Node b = Node.createLiteral( "10", "", dt2 );
        assertDiffer( "types must make a difference", a, b );
        assertTrue( "A and B must express the same value", a.sameValueAs( b ) );
        assertTrue( "matching literals must respect sameValueAs", a.matches( b ) );
View Full Code Here

        assertTrue( "matching literals must respect sameValueAs", a.matches( b ) );
        }
       
    public void testLiteralToString()
        {
        TypeMapper tm = TypeMapper.getInstance();
        RDFDatatype dtInt = tm.getTypeByValue( new Integer( 10 ) );
        Node plain = Node.createLiteral( "rhubarb", "", false );   
        Node english = Node.createLiteral( "eccentric", "en_UK", false );
        Node typed = Node.createLiteral( "10", "", dtInt );
        assertEquals( "\"rhubarb\"", plain.toString() );
        assertEquals( "rhubarb", plain.toString( false ) );
View Full Code Here

     * Test a user error report concerning date/time literals
     */
    public void testDateTimeBug() {
        // Bug in serialization
        String XSDDateURI = XSD.date.getURI();
        TypeMapper typeMapper=TypeMapper.getInstance();
        RDFDatatype dt = typeMapper.getSafeTypeByName(XSDDateURI);
        Object obj = dt.parse("2003-05-21");
        Literal literal = m.createTypedLiteral(obj, dt);       
        literal.toString();    
        Object value2 = dt.parse(obj.toString());
        assertEquals(obj, value2);
View Full Code Here

        assertFalse( "", Node.ANY.matches( null ) );
        }
       
    public void testDataMatches()
        {
        TypeMapper tm = TypeMapper.getInstance();
        RDFDatatype dt1 = tm.getTypeByValue( new Integer( 10 ) );
        RDFDatatype dt2 = tm.getTypeByValue( new Short( (short) 10 ) );
        Node a = NodeFactory.createLiteral( "10", "", dt1 );
        Node b = NodeFactory.createLiteral( "10", "", dt2 );
        assertDiffer( "types must make a difference", a, b );
        assertTrue( "A and B must express the same value", a.sameValueAs( b ) );
        assertTrue( "matching literals must respect sameValueAs", a.matches( b ) );
View Full Code Here

        assertTrue( "matching literals must respect sameValueAs", a.matches( b ) );
        }
       
    public void testLiteralToString()
        {
        TypeMapper tm = TypeMapper.getInstance();
        RDFDatatype dtInt = tm.getTypeByValue( new Integer( 10 ) );
        Node plain = NodeFactory.createLiteral( "rhubarb", "", false );   
        Node english = NodeFactory.createLiteral( "eccentric", "en_UK", false );
        Node typed = NodeFactory.createLiteral( "10", "", dtInt );
        assertEquals( "\"rhubarb\"", plain.toString() );
        assertEquals( "rhubarb", plain.toString( false ) );
View Full Code Here

     * but is not specific to DAML+OIL.
     */
    public void testUserDefined() throws IOException {
        String uri = "http://www.daml.org/2001/03/daml+oil-ex-dt";
        String filename = "testing/xsd/daml+oil-ex-dt.xsd";
        TypeMapper tm = TypeMapper.getInstance();
        List<String> typenames = XSDDatatype.loadUserDefined(uri, new FileReader(filename), null, tm);
        assertIteratorValues(typenames.iterator(), new Object[] {
            uri + "#XSDEnumerationHeight",
            uri + "#over12",
            uri + "#over17",
            uri + "#over59",
            uri + "#clothingsize"   });
       
        // Check the string restriction
        RDFDatatype heightType = tm.getSafeTypeByName(uri + "#XSDEnumerationHeight");
        checkLegalLiteral("short", heightType, String.class, "short");
        checkLegalLiteral("tall", heightType, String.class, "tall");
        checkIllegalLiteral("shortish", heightType);

        // Check the numeric restriction
        RDFDatatype over12Type = tm.getSafeTypeByName(uri + "#over12");
        checkLegalLiteral("15", over12Type, Integer.class, new Integer(15));
        checkIllegalLiteral("12", over12Type);
       
        // Check the union type
        RDFDatatype clothingsize = tm.getSafeTypeByName(uri + "#clothingsize");
        checkLegalLiteral("42", clothingsize, Integer.class, new Integer(42));
        checkLegalLiteral("short", clothingsize, String.class, "short");
       
        // Check use of isValidLiteral for base versus derived combinations
        LiteralLabel iOver12 = m.createTypedLiteral("13", over12Type).asNode().getLiteral();
View Full Code Here

     * Test a user error report concerning date/time literals
     */
    public void testDateTimeBug() {
        // Bug in serialization
        String XSDDateURI = XSD.date.getURI();
        TypeMapper typeMapper=TypeMapper.getInstance();
        RDFDatatype dt = typeMapper.getSafeTypeByName(XSDDateURI);
        Object obj = dt.parse("2003-05-21");
        Literal literal = m.createTypedLiteral(obj, dt);       
        literal.toString();    
        Object value2 = dt.parse(obj.toString());
        assertEquals(obj, value2);
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.datatypes.TypeMapper

Copyright © 2018 www.massapicom. 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.