private String literalToString(Value v) { if (!(v instanceof Literal)) { throw new IllegalArgumentException( "value [" + v + "] was not a literal, which is expected " + "for a parameter of type String." ); } Literal literal = (Literal) v; return literal.stringValue(); }
/** * Get the string value * * @param func function * @param v value * @return string * @throws ValueExprEvaluationException */ public static String getString(Function func, Value v) throws ValueExprEvaluationException { Literal l = getLiteral(func, v, XMLSchema.STRING); return l.stringValue(); }
/** * Get the string value * * @param func * function * @param v * value * @return string * @throws ValueExprEvaluationException */ public static String getString(Function func, Value v) throws ValueExprEvaluationException { Literal l = getLiteral(func, v, XMLSchema.STRING); return l.stringValue(); }
final Matcher matcher = Pattern.compile("\\[(.*)\\,(.*)\\].*").matcher(literalValue.stringValue()); if (matcher.find()) { try { outputDateTimes[0] = DateTime.parse(literalValue.stringValue()); outputDateTimes[1] = null;
ps.print(literal.stringValue()); ps.print('"');
/** * Creates a copy tool run time {@link RyaStatement} from the specified {@link Date}. * @param date the copy tool run time {@link Date}. * @return the {@link RyaStatement} for the copy tool run time. */ public static RyaStatement createCopyToolRunTimeRyaStatement(final Date date) { final Literal literal = VALUE_FACTORY.createLiteral(date != null ? date : DEFAULT_DATE); final RyaType timeObject = new RyaType(literal.getDatatype(), literal.stringValue()); return new RyaStatement(RTS_SUBJECT_RYA, RTS_COPY_TOOL_RUN_TIME_PREDICATE_RYA, timeObject); }
/** * Converts a {@link Literal} into a {@link RyaType} representation of the * {@code literal}. * @param literal the {@link Literal} to convert. * @return the {@link RyaType} representation of the {@code literal}. */ public static RyaType convertLiteral(final Literal literal) { if (literal == null) { return null; } if (literal.getDatatype() != null) { if (Literals.isLanguageLiteral(literal)) { final String language = literal.getLanguage().get(); if (Literals.isValidLanguageTag(language)) { return new RyaType(literal.getDatatype(), literal.stringValue(), language); } else { log.warn("Invalid language (" + LogUtils.clean(language) + ") found in Literal. Defaulting to: " + UNDETERMINED_LANGUAGE); // Replace invalid language with "und" return new RyaType(literal.getDatatype(), literal.stringValue(), UNDETERMINED_LANGUAGE); } } return new RyaType(literal.getDatatype(), literal.stringValue()); } return new RyaType(literal.stringValue()); }
/** * Creates a copy tool parent time offset {@link RyaStatement} from the specified offset. * @param timeOffset the copy tool parent time offset. (in milliseconds). * @return the {@link RyaStatement} for the copy tool parent time offset. */ public static RyaStatement createTimeOffsetRyaStatement(final long timeOffset) { final Literal literal = VALUE_FACTORY.createLiteral(timeOffset); final RyaType timeObject = new RyaType(literal.getDatatype(), literal.stringValue()); return new RyaStatement(RTS_SUBJECT_RYA, RTS_TIME_OFFSET_PREDICATE_RYA, timeObject); }
/** * Creates a copy tool split time {@link RyaStatement} from the specified {@link Date}. * @param date the copy tool split time {@link Date}. * @return the {@link RyaStatement} for the copy tool split time. */ public static RyaStatement createCopyToolSplitTimeRyaStatement(final Date date) { final Literal literal = VALUE_FACTORY.createLiteral(date != null ? date : DEFAULT_DATE); final RyaType timeObject = new RyaType(literal.getDatatype(), literal.stringValue()); return new RyaStatement(RTS_SUBJECT_RYA, RTS_COPY_TOOL_SPLIT_TIME_PREDICATE_RYA, timeObject); }
throw new ValueExprEvaluationException("Second list element must be a literal"); final String s = ((Literal)args[0]).stringValue(); final String regex = ((Literal)args[1]).stringValue(); final String[] parts = s.split(regex); return new CloseableIteratorIteration<List<? extends Value>, QueryEvaluationException>(
/** * Helper method that adds a literal property to a node. * * @param n the <i>HTML</i> node from which the property value has been extracted. * @param subject subject the property subject. * @param property the property IRI. * @param literal value the property value. * @return returns <code>true</code> if the literal has been accepted and added, <code>false</code> otherwise. */ protected boolean conditionallyAddLiteralProperty( Node n, Resource subject, IRI property, Literal literal ) { final String literalStr = literal.stringValue(); if( containsScriptBlock(literalStr) ) { out.notifyIssue( IssueReport.IssueLevel.WARNING, String.format("Detected script in literal: [%s]", literalStr) , -1 , -1 ); return false; } out.writeTriple(subject, property, literal); TagSoupExtractionResult tser = (TagSoupExtractionResult) out; tser.addPropertyPath(this.getClass(), subject, property, null, DomUtils.getXPathListForNode(n) ); return true; }
@Override public void parse(Model graph, Resource implNode) throws SailConfigException { super.parse(graph, implNode); try { Models.objectLiteral(graph.filter(implNode, EVALUATION_STRATEGY_FACTORY, null)).ifPresent( factoryClassName -> { setEvaluationStrategyFactoryClassName(factoryClassName.stringValue()); }); } catch (ModelException e) { throw new SailConfigException(e.getMessage(), e); } } }
super.parse(graph, implNode); Optional<Literal> tablespaceValue = backCompatibilityFilterObjectLiteral(graph, implNode, HALYARD.TABLE_NAME_PROPERTY); if (tablespaceValue.isPresent() && tablespaceValue.get().stringValue().length() > 0) { setTablespace(tablespaceValue.get().stringValue()); } else { Optional<Resource> delegate = Models.subject(graph.filter(null, SailConfigSchema.DELEGATE, implNode)); Optional<Literal> idValue = Models.objectLiteral(graph.filter(repoImpl.get(), RepositoryConfigSchema.REPOSITORYID, null)); if (idValue.isPresent()) { setTablespace(idValue.get().stringValue()); setElasticIndexURL(elasticIndexValue.get().stringValue());
setQueryLanguage(QueryLanguage.valueOf(language.get().stringValue())); if (null == getQueryLanguage()) { throw new SailConfigException("Valid value required for " + QUERY_LANGUAGE if (object.isPresent()) { Models.objectLiteral(m.filter(object.get(), SP.TEXT_PROPERTY, null)).ifPresent( lit -> setRuleQuery(lit.stringValue())); if (object.isPresent()) { Models.objectLiteral(m.filter(object.get(), SP.TEXT_PROPERTY, null)).ifPresent( lit -> setMatcherQuery(lit.stringValue()));
private Object getObjectValue(Literal object) { IRI datatype = object.getDatatype(); if (datatype.equals(XMLSchema.INT) || datatype.equals(XMLSchema.INTEGER) || datatype.equals(XMLSchema.LONG)){ return object.longValue(); } else if (datatype.equals(XMLSchema.DECIMAL) || datatype.equals(XMLSchema.DOUBLE) || datatype.equals(XMLSchema.FLOAT)) { return object.doubleValue(); } else if (datatype.equals(XMLSchema.BOOLEAN)) { return object.booleanValue(); } else { // it's a string, and it can be tagged with language info. // if a language filter has been defined we apply it here final Optional<String> language = object.getLanguage(); if(langFilter == null || !language.isPresent() || (language.isPresent() && langFilter.equals(language.get()))){ return object.stringValue(); } return null; //string is filtered } }
private Object getObjectValue(Literal object) { IRI datatype = object.getDatatype(); if (datatype.equals(XMLSchema.INT) || datatype.equals(XMLSchema.INTEGER) || datatype.equals(XMLSchema.LONG)){ return object.longValue(); } else if (datatype.equals(XMLSchema.DECIMAL) || datatype.equals(XMLSchema.DOUBLE) || datatype.equals(XMLSchema.FLOAT)) { return object.doubleValue(); } else if (datatype.equals(XMLSchema.BOOLEAN)) { return object.booleanValue(); } else { // it's a string, and it can be tagged with language info. // if a language filter has been defined we apply it here final Optional<String> language = object.getLanguage(); if(langFilter == null || !language.isPresent() || (language.isPresent() && langFilter.equals(language.get()))){ return object.stringValue(); } return null; //string is filtered } }
@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()); }
public static Node asNode(Value v) { Node node; if (v == null) { node = Node.ANY; // TODO or Node.NULL or null? } else if (v instanceof IRI) { node = NodeFactory.createURI(v.stringValue()); } else if (v instanceof BNode) { node = NodeFactory.createBlankNode(((BNode) v).getID()); } else if (v instanceof Literal) { Literal lit = (Literal) v; IRI datatype = lit.getDatatype(); String lang = lit.getLanguage().orElse(null); if (lang != null) { node = NodeFactory.createLiteral(lit.getLabel(), lang, null); } else if (datatype != null) { node = NodeFactory.createLiteral(lit.getLabel(), null, NodeFactory.getType(datatype.toString())); } else { node = NodeFactory.createLiteral(lit.stringValue()); } } else { throw new IllegalArgumentException("Cannot create Node from Value: " + v); } return node; }
@Test @Category(TestSuites.Prepush.class) public void getRepositoryUsingManager() throws Exception { final Path confDir = Files.createTempDirectory("repomgr"); closeLater(() -> FileUtils.deleteDirectory(confDir.toFile())); RepositoryManager manager = new LocalRepositoryManager(confDir.toFile()); manager.initialize(); closeLater(manager::shutDown); Model graph = parseTurtleGraph(configFile); updateGraphForTestServer(graph); // Cleanup AGRepositoryConfig agConfig = getConfig(graph); deleteLater(agConfig.getRepositoryId(), agConfig.getCatalogId()); Resource node = GraphUtil.getUniqueSubject(graph, RDF.TYPE, RepositoryConfigSchema.REPOSITORY); String id = GraphUtil.getUniqueObjectLiteral(graph, node, RepositoryConfigSchema.REPOSITORYID).stringValue(); RepositoryConfig config = RepositoryConfig.create(graph, node); config.validate(); manager.addRepositoryConfig(config); Repository repo = manager.getRepository(id); repo.initialize(); closeLater(repo::shutDown); Assert.assertEquals(0, repo.getConnection().size()); }