Java Code Examples for org.eclipse.rdf4j.model.vocabulary.XMLSchema#LONG

The following examples show how to use org.eclipse.rdf4j.model.vocabulary.XMLSchema#LONG . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccumuloRyaDAOTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void testLiteralTypes() throws Exception {
    RyaIRI cpu = new RyaIRI(litdupsNS + "cpu");
    RyaIRI loadPerc = new RyaIRI(litdupsNS + "loadPerc");
    RyaType longLit = new RyaType(XMLSchema.LONG, "3");

    dao.add(new RyaStatement(cpu, loadPerc, longLit));

    AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine();

    CloseableIteration<RyaStatement, RyaDAOException> query = queryEngine.query(new RyaStatement(cpu, null, null), conf);
    assertTrue(query.hasNext());
    RyaStatement next = query.next();
    assertEquals(new Long(longLit.getData()), new Long(next.getObject().getData()));
    query.close();

    RyaType doubleLit = new RyaType(XMLSchema.DOUBLE, "2.0");

    dao.add(new RyaStatement(cpu, loadPerc, doubleLit));

    query = queryEngine.query(new RyaStatement(cpu, loadPerc, doubleLit), conf);
    assertTrue(query.hasNext());
    next = query.next();
    assertEquals(Double.parseDouble(doubleLit.getData()), Double.parseDouble(next.getObject().getData()), 0.001);
    query.close();
}
 
Example 2
Source File: AccumuloRyaDAOTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void testSameLiteralStringTypes() throws Exception {
    RyaIRI cpu = new RyaIRI(litdupsNS + "cpu");
    RyaIRI loadPerc = new RyaIRI(litdupsNS + "loadPerc");
    RyaType longLit = new RyaType(XMLSchema.LONG, "10");
    RyaType strLit = new RyaType(XMLSchema.STRING, new String(RyaContext.getInstance().serializeType(longLit)[0]));

    RyaStatement expected = new RyaStatement(cpu, loadPerc, longLit);
    dao.add(expected);
    dao.add(new RyaStatement(cpu, loadPerc, strLit));

    AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine();

    CloseableIteration<RyaStatement, RyaDAOException> query = queryEngine.query(new RyaStatement(cpu, loadPerc, longLit), conf);
    assertTrue(query.hasNext());
    RyaStatement next = query.next();
    assertEquals(new Long(longLit.getData()), new Long(next.getObject().getData()));
    assertEquals(longLit.getDataType(), next.getObject().getDataType());
    assertFalse(query.hasNext());
    query.close();
}
 
Example 3
Source File: SmartUriAdapter.java    From rya with Apache License 2.0 6 votes vote down vote up
private static IRI determineType(final String data) {
    if (Ints.tryParse(data) != null) {
        return XMLSchema.INTEGER;
    } else if (Doubles.tryParse(data) != null) {
        return XMLSchema.DOUBLE;
    } else if (Floats.tryParse(data) != null) {
        return XMLSchema.FLOAT;
    } else if (isShort(data)) {
        return XMLSchema.SHORT;
    } else if (Longs.tryParse(data) != null) {
        return XMLSchema.LONG;
    } if (Boolean.parseBoolean(data)) {
        return XMLSchema.BOOLEAN;
    } else if (isByte(data)) {
        return XMLSchema.BYTE;
    } else if (isDate(data)) {
        return XMLSchema.DATETIME;
    } else if (isUri(data)) {
        return XMLSchema.ANYURI;
    }

    return XMLSchema.STRING;
}
 
Example 4
Source File: NumericMemLiteral.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public NumericMemLiteral(Object creator, long n) {
	this(creator, n, XMLSchema.LONG);
}
 
Example 5
Source File: LongCast.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected IRI getXsdDatatype() {
	return XMLSchema.LONG;
}
 
Example 6
Source File: NumericLiteral.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Creates an xsd:long typed litral with the specified value.
 */
protected NumericLiteral(long n) {
	this(n, XMLSchema.LONG);
}
 
Example 7
Source File: LongRyaTypeResolver.java    From rya with Apache License 2.0 4 votes vote down vote up
public LongRyaTypeResolver() {
    super((byte) LONG_LITERAL_MARKER, XMLSchema.LONG);
}
 
Example 8
Source File: AbstractTriplePatternStrategyTest.java    From rya with Apache License 2.0 4 votes vote down vote up
public void testObjectTypeInfo() throws Exception {
    RyaIRI subj = new RyaIRI("urn:test#1234");
    RyaIRI pred = new RyaIRI("urn:test#pred");
    RyaType obj = new RyaType(XMLSchema.LONG, "10");
    RyaStatement ryaStatement = new RyaStatement(subj, pred, obj);
    Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = RyaTripleContext.getInstance(new MockRdfConfiguration()).serializeTriple(ryaStatement);
    TripleRow tripleRow = serialize.get(SPO);

    String row = new String(tripleRow.getRow());
    TriplePatternStrategy spoStrategy = new SpoWholeRowTriplePatternStrategy();
    //obj
    byte[][] bytes = RyaContext.getInstance().serializeType(obj);
    String objStr = new String(bytes[0]);
    byte[] objectTypeInfo = bytes[1];
    TripleRowRegex tripleRowRegex = spoStrategy.buildRegex(null, null,
            objStr
            , null, objectTypeInfo);
    Pattern p = Pattern.compile(tripleRowRegex.getRow());
    Matcher matcher = p.matcher(row);
    assertTrue(matcher.matches());

    //build row with same object str data
    Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> dupTriple_str = RyaTripleContext.getInstance(new MockRdfConfiguration()).serializeTriple(
            new RyaStatement(subj, pred, new RyaType(XMLSchema.STRING, objStr))
    );
    TripleRow tripleRow_dup_str = dupTriple_str.get(SPO);

    row = new String(tripleRow_dup_str.getRow());
    spoStrategy = new SpoWholeRowTriplePatternStrategy();

    tripleRowRegex = spoStrategy.buildRegex(null, null,
            objStr
            , null, objectTypeInfo);
    p = Pattern.compile(tripleRowRegex.getRow());
    matcher = p.matcher(row);
    assertFalse(matcher.matches());

    //po table
    TriplePatternStrategy poStrategy = new PoWholeRowTriplePatternStrategy();
    tripleRowRegex = poStrategy.buildRegex(null, null,
            objStr
            , null, objectTypeInfo);
    p = Pattern.compile(tripleRowRegex.getRow());
    String po_row = new String(serialize.get(PO).getRow());
    matcher = p.matcher(po_row);
    assertTrue(matcher.matches());

    tripleRowRegex = poStrategy.buildRegex(null, null,
            objStr
            , null, objectTypeInfo);
    p = Pattern.compile(tripleRowRegex.getRow());
    matcher = p.matcher(new String(dupTriple_str.get(PO).getRow()));
    assertFalse(matcher.matches());

    //osp table
    TriplePatternStrategy ospStrategy = new OspWholeRowTriplePatternStrategy();
    tripleRowRegex = ospStrategy.buildRegex(null, null,
            objStr
            , null, objectTypeInfo);
    p = Pattern.compile(tripleRowRegex.getRow());
    String osp_row = new String(serialize.get(OSP).getRow());
    matcher = p.matcher(osp_row);
    assertTrue(matcher.matches());

    tripleRowRegex = ospStrategy.buildRegex(null, null,
            objStr
            , null, objectTypeInfo);
    p = Pattern.compile(tripleRowRegex.getRow());
    matcher = p.matcher(new String(dupTriple_str.get(OSP).getRow()));
    assertFalse(matcher.matches());
}
 
Example 9
Source File: DuplicateDataDetector.java    From rya with Apache License 2.0 4 votes vote down vote up
@Override
public IRI getXmlSchemaUri() {
    return XMLSchema.LONG;
}
 
Example 10
Source File: RyaTypeUtils.java    From rya with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a long {@link RyaType} object.
 * @param value the {@link Long} object.
 * @return the {@link RyaType} with the data type set to
 * {@link XMLSchema#LONG} and the data set to the specified {@code value}.
 */
public static RyaType longRyaType(final Long value) {
    return new RyaType(XMLSchema.LONG, Long.toString(value));
}