Java Code Examples for org.eclipse.rdf4j.model.vocabulary.XMLSchema#INTEGER
The following examples show how to use
org.eclipse.rdf4j.model.vocabulary.XMLSchema#INTEGER .
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: SpinParser.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
private int getMaxIterationCount(Resource ruleProp, TripleSource store) throws RDF4JException { Value v = TripleSources.singleValue(ruleProp, SPIN.RULE_PROPERTY_MAX_ITERATION_COUNT_PROPERTY, store); if (v == null) { return -1; } else if (v instanceof Literal) { try { return ((Literal) v).intValue(); } catch (NumberFormatException e) { throw new MalformedSpinException("Value for " + SPIN.RULE_PROPERTY_MAX_ITERATION_COUNT_PROPERTY + " must be of datatype " + XMLSchema.INTEGER + ": " + ruleProp); } } else { throw new MalformedSpinException( "Non-literal value for " + SPIN.RULE_PROPERTY_MAX_ITERATION_COUNT_PROPERTY + ": " + ruleProp); } }
Example 2
Source File: SPARQLResultsXSVMappingStrategy.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * This method parses a number as matched by {@link #numberPattern} into a {@link Value}. * * @param valueString The string to be parsed into a number * @return The parsed value */ protected Value parseNumberPatternMatch(String valueString) { IRI dataType = null; if (XMLDatatypeUtil.isValidInteger(valueString)) { if (XMLDatatypeUtil.isValidNegativeInteger(valueString)) { dataType = XMLSchema.NEGATIVE_INTEGER; } else { dataType = XMLSchema.INTEGER; } } else if (XMLDatatypeUtil.isValidDecimal(valueString)) { dataType = XMLSchema.DECIMAL; } else if (XMLDatatypeUtil.isValidDouble(valueString)) { dataType = XMLSchema.DOUBLE; } return dataType != null ? valueFactory.createLiteral(valueString, dataType) : valueFactory.createLiteral(valueString); }
Example 3
Source File: SmartUriAdapter.java From rya with Apache License 2.0 | 6 votes |
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: EntityCentricIndexTest.java From rya with Apache License 2.0 | 5 votes |
@BeforeClass public static void init() throws RyaTypeResolverException { String subjectStr = ":subject"; String predicateStr = ":predicate"; RyaType object = new RyaType(XMLSchema.INTEGER, "3"); byte[][] objectBytes = RyaContext.getInstance().serializeType(object); String contextStr = "http://example.org/graph"; // no qualifier since entity-centric index doesn't store an actual column qualifier long timestamp = (long) 123456789; byte[] visibilityBytes = "test_visibility".getBytes(); byte[] valueBytes = "test_value".getBytes(); subjectCentricKey = new Key( subjectStr.getBytes(), predicateStr.getBytes(), Bytes.concat(contextStr.getBytes(), DELIM_BYTES, "object".getBytes(), DELIM_BYTES, objectBytes[0], objectBytes[1]), visibilityBytes, timestamp); objectCentricKey = new Key( objectBytes[0], predicateStr.getBytes(), Bytes.concat(contextStr.getBytes(), DELIM_BYTES, "subject".getBytes(), DELIM_BYTES, subjectStr.getBytes(), objectBytes[1]), visibilityBytes, timestamp); ryaStatement = new RyaStatement( new RyaIRI(subjectStr), new RyaIRI(predicateStr), new RyaType(XMLSchema.INTEGER, "3"), new RyaIRI(contextStr), null, visibilityBytes, valueBytes, timestamp); value = new Value(valueBytes); }
Example 5
Source File: IntegerMemLiteral.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
public IntegerMemLiteral(Object creator, BigInteger value) { this(creator, value, XMLSchema.INTEGER); }
Example 6
Source File: IntegerCast.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected IRI getXsdDatatype() { return XMLSchema.INTEGER; }
Example 7
Source File: IntegerLiteral.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Creates an xsd:integer literal with the specified value. */ protected IntegerLiteral(BigInteger value) { this(value, XMLSchema.INTEGER); }
Example 8
Source File: TurtleParser.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
protected Literal parseNumber() throws IOException, RDFParseException { StringBuilder value = getBuilder(); IRI datatype = XMLSchema.INTEGER; int c = readCodePoint(); // read optional sign character if (c == '+' || c == '-') { appendCodepoint(value, c); c = readCodePoint(); } while (ASCIIUtil.isNumber(c)) { appendCodepoint(value, c); c = readCodePoint(); } if (c == '.' || c == 'e' || c == 'E') { // read optional fractional digits if (c == '.') { if (TurtleUtil.isWhitespace(peekCodePoint())) { // We're parsing an integer that did not have a space before // the // period to end the statement } else { appendCodepoint(value, c); c = readCodePoint(); while (ASCIIUtil.isNumber(c)) { appendCodepoint(value, c); c = readCodePoint(); } if (value.length() == 1) { // We've only parsed a '.' reportFatalError("Object for statement missing"); } // We're parsing a decimal or a double datatype = XMLSchema.DECIMAL; } } else { if (value.length() == 0) { // We've only parsed an 'e' or 'E' reportFatalError("Object for statement missing"); } } // read optional exponent if (c == 'e' || c == 'E') { datatype = XMLSchema.DOUBLE; appendCodepoint(value, c); c = readCodePoint(); if (c == '+' || c == '-') { appendCodepoint(value, c); c = readCodePoint(); } if (!ASCIIUtil.isNumber(c)) { reportError("Exponent value missing", BasicParserSettings.VERIFY_DATATYPE_VALUES); } appendCodepoint(value, c); c = readCodePoint(); while (ASCIIUtil.isNumber(c)) { appendCodepoint(value, c); c = readCodePoint(); } } } // Unread last character, it isn't part of the number unread(c); // String label = value.toString(); // if (datatype.equals(XMLSchema.INTEGER)) { // try { // label = XMLDatatypeUtil.normalizeInteger(label); // } // catch (IllegalArgumentException e) { // // Note: this should never happen because of the parse constraints // reportError("Illegal integer value: " + label); // } // } // return createLiteral(label, null, datatype); // Return result as a typed literal return createLiteral(value.toString(), null, datatype, getLineNumber(), -1); }
Example 9
Source File: IntegerRyaTypeResolver.java From rya with Apache License 2.0 | 4 votes |
public IntegerRyaTypeResolver() { super((byte) INTEGER_LITERAL_MARKER, XMLSchema.INTEGER); }
Example 10
Source File: KafkaRyaSubGraphExportIT.java From rya with Apache License 2.0 | 4 votes |
@Test public void nestedConstructQuery() throws Exception { // A query that groups what is aggregated by one of the keys. final String sparql = "CONSTRUCT { " + "_:b a <urn:highSpeedTrafficArea> . " + "_:b <urn:hasCount> ?obsCount . " + "_:b <urn:hasLocation> ?location ." + "_:b <urn:hasAverageVelocity> ?avgVelocity ." + "} WHERE { " + "FILTER(?obsCount > 1) " + "{ " + "SELECT ?location (count(?obs) AS ?obsCount) (avg(?velocity) AS ?avgVelocity) " + "WHERE { " + "FILTER(?velocity > 75) " + "?obs <urn:hasVelocity> ?velocity. " + "?obs <urn:hasLocation> ?location. " + "}GROUP BY ?location }}"; // Create the Statements that will be loaded into Rya. final ValueFactory vf = SimpleValueFactory.getInstance(); final Collection<Statement> statements = Sets.newHashSet( vf.createStatement(vf.createIRI("urn:obs1"), vf.createIRI("urn:hasVelocity"), vf.createLiteral(77)), vf.createStatement(vf.createIRI("urn:obs1"), vf.createIRI("urn:hasLocation"), vf.createLiteral("OldTown")), vf.createStatement(vf.createIRI("urn:obs2"), vf.createIRI("urn:hasVelocity"), vf.createLiteral(81)), vf.createStatement(vf.createIRI("urn:obs2"), vf.createIRI("urn:hasLocation"), vf.createLiteral("OldTown")), vf.createStatement(vf.createIRI("urn:obs3"), vf.createIRI("urn:hasVelocity"), vf.createLiteral(70)), vf.createStatement(vf.createIRI("urn:obs3"), vf.createIRI("urn:hasLocation"), vf.createLiteral("OldTown")), vf.createStatement(vf.createIRI("urn:obs5"), vf.createIRI("urn:hasVelocity"), vf.createLiteral(87)), vf.createStatement(vf.createIRI("urn:obs5"), vf.createIRI("urn:hasLocation"), vf.createLiteral("Rosslyn")), vf.createStatement(vf.createIRI("urn:obs6"), vf.createIRI("urn:hasVelocity"), vf.createLiteral(81)), vf.createStatement(vf.createIRI("urn:obs6"), vf.createIRI("urn:hasLocation"), vf.createLiteral("Rosslyn")), vf.createStatement(vf.createIRI("urn:obs7"), vf.createIRI("urn:hasVelocity"), vf.createLiteral(67)), vf.createStatement(vf.createIRI("urn:obs7"), vf.createIRI("urn:hasLocation"), vf.createLiteral("Clarendon")), vf.createStatement(vf.createIRI("urn:obs8"), vf.createIRI("urn:hasVelocity"), vf.createLiteral(77)), vf.createStatement(vf.createIRI("urn:obs8"), vf.createIRI("urn:hasLocation"), vf.createLiteral("Ballston")), vf.createStatement(vf.createIRI("urn:obs9"), vf.createIRI("urn:hasVelocity"), vf.createLiteral(87)), vf.createStatement(vf.createIRI("urn:obs9"), vf.createIRI("urn:hasLocation"), vf.createLiteral("FallsChurch"))); // Create the PCJ in Fluo and load the statements into Rya. final String pcjId = loadStatements(sparql, statements); // Verify the end results of the query match the expected results. final Set<RyaSubGraph> results = readAllResults(pcjId); RyaStatement statement1 = new RyaStatement(new RyaIRI("urn:obs1"), new RyaIRI("urn:hasCount"), new RyaType(XMLSchema.INTEGER, "2")); RyaStatement statement2 = new RyaStatement(new RyaIRI("urn:obs1"), new RyaIRI("urn:hasAverageVelocity"), new RyaType(XMLSchema.DECIMAL, "84")); RyaStatement statement3 = new RyaStatement(new RyaIRI("urn:obs1"), new RyaIRI("urn:hasLocation"), new RyaType("Rosslyn")); RyaStatement statement4 = new RyaStatement(new RyaIRI("urn:obs1"), new RyaIRI(RDF.TYPE.toString()), new RyaIRI("urn:highSpeedTrafficArea")); RyaStatement statement5 = new RyaStatement(new RyaIRI("urn:obs2"), new RyaIRI("urn:hasCount"), new RyaType(XMLSchema.INTEGER, "2")); RyaStatement statement6 = new RyaStatement(new RyaIRI("urn:obs2"), new RyaIRI("urn:hasAverageVelocity"), new RyaType(XMLSchema.DECIMAL, "79")); RyaStatement statement7 = new RyaStatement(new RyaIRI("urn:obs2"), new RyaIRI("urn:hasLocation"), new RyaType("OldTown")); RyaStatement statement8 = new RyaStatement(new RyaIRI("urn:obs2"), new RyaIRI(RDF.TYPE.toString()), new RyaIRI("urn:highSpeedTrafficArea")); final Set<RyaSubGraph> expectedResults = new HashSet<>(); RyaSubGraph subGraph1 = new RyaSubGraph(pcjId); Set<RyaStatement> stmnts1 = new HashSet<>(Arrays.asList(statement1, statement2, statement3, statement4)); subGraph1.setStatements(stmnts1); expectedResults.add(subGraph1); RyaSubGraph subGraph2 = new RyaSubGraph(pcjId); Set<RyaStatement> stmnts2 = new HashSet<>(Arrays.asList(statement5, statement6, statement7, statement8)); subGraph2.setStatements(stmnts2); expectedResults.add(subGraph2); Assert.assertEquals(expectedResults.size(), results.size()); ConstructGraphTestUtils.subGraphsEqualIgnoresBlankNode(expectedResults, results); }
Example 11
Source File: DuplicateDataDetector.java From rya with Apache License 2.0 | 4 votes |
@Override public IRI getXmlSchemaUri() { return XMLSchema.INTEGER; }
Example 12
Source File: RyaTypeUtils.java From rya with Apache License 2.0 | 2 votes |
/** * Creates an integer {@link RyaType} object. * @param value the {@link Integer} object. * @return the {@link RyaType} with the data type set to * {@link XMLSchema#INTEGER} and the data set to the specified * {@code value}. */ public static RyaType intRyaType(final Integer value) { return new RyaType(XMLSchema.INTEGER, Integer.toString(value)); }