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

The following examples show how to use org.eclipse.rdf4j.model.vocabulary.XMLSchema#STRING . 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: 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 2
Source File: StrictEvaluationStrategy.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Value evaluate(Datatype node, BindingSet bindings)
		throws QueryEvaluationException {
	Value v = evaluate(node.getArg(), bindings);

	if (v instanceof Literal) {
		Literal literal = (Literal) v;

		if (literal.getDatatype() != null) {
			// literal with datatype
			return literal.getDatatype();
		} else if (literal.getLanguage().isPresent()) {
			return RDF.LANGSTRING;
		} else {
			// simple literal
			return XMLSchema.STRING;
		}

	}

	throw new ValueExprEvaluationException();
}
 
Example 3
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 4
Source File: HalyardValueExprEvaluation.java    From Halyard with Apache License 2.0 6 votes vote down vote up
/**
 * Evaluate a {@link Datatype} node
 * @param node the node to evaluate
 * @param bindings the set of named value bindings
 * @return a {@link Literal} representing the evaluation of the argument of the {@link Datatype}.
 * @throws ValueExprEvaluationException
 * @throws QueryEvaluationException
 */
private Value evaluate(Datatype node, BindingSet bindings) throws ValueExprEvaluationException, QueryEvaluationException {
    Value v = evaluate(node.getArg(), bindings);
    if (v instanceof Literal) {
        Literal literal = (Literal) v;
        if (literal.getDatatype() != null) {
            // literal with datatype
            return literal.getDatatype();
        } else if (literal.getLanguage() != null) {
            return RDF.LANGSTRING;
        } else {
            // simple literal
            return XMLSchema.STRING;
        }
    }
    throw new ValueExprEvaluationException();
}
 
Example 5
Source File: MongoEntityIndexerIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void addStatement_setsProperty() throws Exception {
    try(MongoEntityIndexer indexer = new MongoEntityIndexer()) {
        indexer.setConf(conf);
        indexer.init();
        // Load the types into the TypeStorage.
        final TypeStorage types = new MongoTypeStorage(getMongoClient(), conf.getRyaInstanceName());
        types.create(PERSON_TYPE);
        types.create(EMPLOYEE_TYPE);

        // Index a RyaStatement that will create an Entity with two implicit types.
        final RyaStatement statement = new RyaStatement(new RyaIRI("urn:SSN/111-11-1111"), new RyaIRI("urn:name"), new RyaType(XMLSchema.STRING, "Alice"));
        indexer.storeStatement(statement);

        // Fetch the Entity from storage and ensure it looks correct.
        final EntityStorage entities = new MongoEntityStorage(getMongoClient(), conf.getRyaInstanceName());
        final Entity entity = entities.get(new RyaIRI("urn:SSN/111-11-1111")).get();

        final Entity expected = Entity.builder()
                .setSubject(new RyaIRI("urn:SSN/111-11-1111"))
                .setProperty(new RyaIRI("urn:person"), new Property(new RyaIRI("urn:name"), new RyaType(XMLSchema.STRING, "Alice")))
                .setProperty(new RyaIRI("urn:employee"), new Property(new RyaIRI("urn:name"), new RyaType(XMLSchema.STRING, "Alice")))
                .build();

        assertEquals(expected, entity);
    }
}
 
Example 6
Source File: RdfToRyaConversionsTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertLiteral_normalString() {
    final String expectedData = "Hello";
    final Literal literal = VF.createLiteral(expectedData);
    final RyaType ryaType = RdfToRyaConversions.convertLiteral(literal);
    assertEquals(XMLSchema.STRING, ryaType.getDataType());
    assertEquals(expectedData, ryaType.getData());
    final RyaType expectedRyaType = new RyaType(XMLSchema.STRING, expectedData);
    assertEquals(expectedRyaType, ryaType);
    assertNull(ryaType.getLanguage());
}
 
Example 7
Source File: RdfToRyaConversionsTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertLiteral_nullDataType() {
    final Literal literal = mock(SimpleLiteral.class);
    final String expectedData = "Ice Cream";
    when(literal.getLabel()).thenReturn(expectedData);
    when(literal.stringValue()).thenReturn(expectedData);
    // Don't think this is possible but test anyways. Need to mock to force this null value.
    when(literal.getDatatype()).thenReturn(null);
    final RyaType ryaType = RdfToRyaConversions.convertLiteral(literal);
    final RyaType expected = new RyaType(XMLSchema.STRING, expectedData);
    assertEquals(expected, ryaType);
    assertNull(ryaType.getLanguage());
}
 
Example 8
Source File: RyaToRdfConversionsTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertLiteral_normalString() {
    final String expectedData = "Hello";
    final RyaType ryaType = new RyaType(XMLSchema.STRING, expectedData);
    final Literal literal = RyaToRdfConversions.convertLiteral(ryaType);
    assertEquals(XMLSchema.STRING, literal.getDatatype());
    assertEquals(expectedData, literal.getLabel());
    assertFalse(literal.getLanguage().isPresent());
    final Literal expectedLiteral = VF.createLiteral(expectedData);
    assertEquals(expectedLiteral, literal);
}
 
Example 9
Source File: SimpleLiteralTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test method for
 * {@link org.eclipse.rdf4j.model.impl.SimpleLiteral#SimpleLiteral(java.lang.String, org.eclipse.rdf4j.model.IRI)} .
 */
@Test
public final void testStringIRINullString() throws Exception {
	String label = null;
	IRI datatype = XMLSchema.STRING;

	thrown.expect(NullPointerException.class);
	new SimpleLiteral(label, datatype);
}
 
Example 10
Source File: SimpleLiteralTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public final void testStringLiteralEqualsHashCode() {
	// in RDF 1.1, there is no distinction between plain and string-typed literals.
	SimpleLiteral lit1 = new SimpleLiteral("a");
	SimpleLiteral lit2 = new SimpleLiteral("a", XMLSchema.STRING);

	assertEquals(lit1, lit2);
	assertEquals(lit1.hashCode(), lit2.hashCode());
}
 
Example 11
Source File: SimpleLiteral.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a new datatyped literal with the supplied label and datatype.
 *
 * @param label    The label for the literal, must not be <tt>null</tt>.
 * @param datatype The datatype for the literal.
 */
protected SimpleLiteral(String label, IRI datatype) {
	setLabel(label);
	if (RDF.LANGSTRING.equals(datatype)) {
		throw new IllegalArgumentException("datatype rdf:langString requires a language tag");
	} else if (datatype == null) {
		datatype = XMLSchema.STRING;
	}
	setDatatype(datatype);
}
 
Example 12
Source File: RyaTypeResolverImpl.java    From rya with Apache License 2.0 4 votes vote down vote up
public RyaTypeResolverImpl() {
    this((byte) PLAIN_LITERAL_MARKER, XMLSchema.STRING);
}
 
Example 13
Source File: AbstractValueFactory.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Literal createLiteral(String value) {
	return new SimpleLiteral(value, XMLSchema.STRING);
}
 
Example 14
Source File: StringCast.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected IRI getXsdDatatype() {
	return XMLSchema.STRING;
}
 
Example 15
Source File: DuplicateDataDetector.java    From rya with Apache License 2.0 4 votes vote down vote up
@Override
public IRI getXmlSchemaUri() {
    return XMLSchema.STRING;
}
 
Example 16
Source File: ValueStore.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public NativeLiteral createLiteral(String value) {
	return new NativeLiteral(revision, value, XMLSchema.STRING);
}
 
Example 17
Source File: RyaTypeUtils.java    From rya with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a string {@link RyaType} object.
 * @param value the {@link String} object.
 * @return the {@link RyaType} with the data type set to
 * {@link XMLSchema#STRING} and the data set to the specified {@code value}.
 */
public static RyaType stringRyaType(final String value) {
    return new RyaType(XMLSchema.STRING, value);
}
 
Example 18
Source File: RyaType.java    From rya with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new instance of {@link RyaType} of type
 * {@link XMLSchema#STRING} and with no language.
 * @param data the data string.
 */
public RyaType(final String data) {
    this(XMLSchema.STRING, data);
}
 
Example 19
Source File: MemLiteral.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Creates a new Literal which will get the supplied label.
 *
 * @param creator The object that is creating this MemLiteral.
 * @param label   The label for this literal.
 */
public MemLiteral(Object creator, String label) {
	super(label, XMLSchema.STRING);
	this.creator = creator;
}