Java Code Examples for org.apache.jena.rdf.model.ResourceFactory#createResource()
The following examples show how to use
org.apache.jena.rdf.model.ResourceFactory#createResource() .
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: String2Node.java From quetzal with Eclipse Public License 2.0 | 6 votes |
public String2Node(String type, String value) { if(value.equals("NULL")){ node = null; } else if (value.startsWith(Constants.PREFIX_BLANK_NODE)) { AnonId id = new AnonId(value.substring(Constants.PREFIX_BLANK_NODE.length())); node = ModelFactory.createDefaultModel().createResource(id); } else if (type.equals(Constants.NAME_COLUMN_SUBJECT)) { node = ResourceFactory.createResource(value); } else if (type.equals(Constants.NAME_COLUMN_PREDICATE)) { node = ResourceFactory.createProperty(value); } else if (type.equals(Constants.NAME_COLUMN_OBJECT)) { assert (false); // mdb change code call other ctor } }
Example 2
Source File: RDFNodeFactory.java From Processor with Apache License 2.0 | 6 votes |
public static final RDFNode createTyped(String value, Resource valueType) { if (value == null) throw new IllegalArgumentException("Param value cannot be null"); // without value type, return default xsd:string value if (valueType == null) return ResourceFactory.createTypedLiteral(value, XSDDatatype.XSDstring); // if value type is from XSD namespace, value is treated as typed literal with XSD datatype if (valueType.getNameSpace().equals(XSD.getURI())) { RDFDatatype dataType = NodeFactory.getType(valueType.getURI()); return ResourceFactory.createTypedLiteral(value, dataType); } // otherwise, value is treated as URI resource else return ResourceFactory.createResource(value); }
Example 3
Source File: String2Node.java From quetzal with Eclipse Public License 2.0 | 6 votes |
public String2Node(String type, String value, short datatype) { if(value.equals("NULL")){ node = null; } else if (value.startsWith(Constants.PREFIX_BLANK_NODE)) { AnonId id = new AnonId(value.substring(Constants.PREFIX_BLANK_NODE.length())); node = ModelFactory.createDefaultModel().createResource(id); } else if (type.equals(Constants.NAME_COLUMN_SUBJECT)) { node = ResourceFactory.createResource(value); } else if (type.equals(Constants.NAME_COLUMN_PREDICATE)) { node = ResourceFactory.createProperty(value); } else if (type.equals(Constants.NAME_COLUMN_OBJECT)) { assignLiteral(value, datatype); } }
Example 4
Source File: TestCaseWithTargetTest.java From RDFUnit with Apache License 2.0 | 6 votes |
@Parameterized.Parameters(name= "{index}") public static Collection<Object[]> items() { List<String> sparqlSampleQueries = Arrays.asList( "select ?s where{?s ?p ?o }", "select ?s where { ?this ?p ?o ; ?p2 ?o}" ); Resource p = ResourceFactory.createResource("http://example.com#ex"); List<ShapeTarget> targets = Arrays.stream(ShapeTargetType.values()) .filter( sct -> !sct.equals(ShapeTargetType.ValueShapeTarget)) .map(scType -> ShapeTargetCore.create(scType, p)) .collect(Collectors.toList()); Collection<Object[]> parameters = new ArrayList<>(); sparqlSampleQueries .forEach( sparql -> targets .forEach(target -> parameters.add(new Object[] {sparql, target}))); return parameters; }
Example 5
Source File: ShapeTargetCoreTest.java From RDFUnit with Apache License 2.0 | 5 votes |
@Test public void testTargetContainsUri() { Resource uri = ResourceFactory.createResource("http://example.com"); Arrays.stream(ShapeTargetType.values() ) .filter( sct -> !sct.equals(ShapeTargetType.ValueShapeTarget)) .map( s -> ShapeTargetCore.create(s, uri)) .filter( s -> s.getTargetType().hasArgument()) .forEach( s -> { assertThat(s.getPattern()).contains(formatNode(uri)); assertThat(s.getNode()).isEqualTo(uri); }); }
Example 6
Source File: ComponentParameterImplTest.java From RDFUnit with Apache License 2.0 | 5 votes |
@Test public void testGetDefaultValue() { assertThat(argDef.getDefaultValue().isPresent()) .isFalse(); RDFNode node = ResourceFactory.createResource("http://example.com"); ComponentParameterImpl arg2 = ComponentParameterImpl.builder().element(element).predicate(predicate).defaultValue(node).build(); assertThat(arg2.getDefaultValue().get()) .isEqualTo(node); }
Example 7
Source File: CUBE.java From gerbil with GNU Affero General Public License v3.0 | 4 votes |
protected static final Resource resource(String local) { return ResourceFactory.createResource(uri + local); }
Example 8
Source File: DATA_ACCESS_TESTS.java From RDFUnit with Apache License 2.0 | 4 votes |
private static Resource resource(String local) { return ResourceFactory.createResource(namespace + local); }
Example 9
Source File: TagRdfUnitTestGenerator.java From RDFUnit with Apache License 2.0 | 4 votes |
private Optional<TestCase> generateTestFromResult(TestGenerator tg, Pattern tgPattern, QuerySolution row, SchemaSource schemaSource) { Set<String> references = new HashSet<>(); String description; Collection<Binding> bindings = new ArrayList<>(); for (PatternParameter p : tgPattern.getParameters()) { if (row.contains(p.getId())) { RDFNode n = row.get(p.getId()); Binding b; try { b = new Binding(p, n); } catch (NullPointerException | IllegalArgumentException e) { log.error("Non valid binding for parameter {} in AutoGenerator: {}", p.getId(), tg.getUri(), e); continue; } bindings.add(b); if (n.isResource() && !"loglevel".equalsIgnoreCase(p.getId())) { references.add(n.toString().trim().replace(" ", "")); } } else { log.error("Not bindings for parameter {} in AutoGenerator: {}", p.getId(), tg.getUri()); break; } } if (bindings.size() != tg.getPattern().getParameters().size()) { log.error("Bindings for pattern {} do not match in AutoGenerator: {}", tgPattern.getId(), tg.getUri()); return Optional.empty(); } if (row.get("DESCRIPTION") != null) { description = row.get("DESCRIPTION").toString(); } else { log.error("No ?DESCRIPTION variable found in AutoGenerator: {}", tg.getUri()); return Optional.empty(); } Set<ResultAnnotation> patternBindedAnnotations = tgPattern.getBindedAnnotations(bindings); patternBindedAnnotations.addAll(tg.getAnnotations()); Resource tcResource = ResourceFactory.createResource(TestUtils.generateTestURI(schemaSource.getPrefix(), tgPattern, bindings, tg.getUri())); PatternBasedTestCaseImpl tc = new PatternBasedTestCaseImpl( tcResource, new TestCaseAnnotation( tcResource, TestGenerationType.AutoGenerated, tg.getUri(), schemaSource.getSourceType(), schemaSource.getUri(), references, description, null, patternBindedAnnotations), tgPattern, bindings ); new TestCaseValidator(tc).validate(); return Optional.of(tc); }
Example 10
Source File: RLOG.java From RDFUnit with Apache License 2.0 | 4 votes |
private static Resource resource(String local) { return ResourceFactory.createResource(namespace + local); }
Example 11
Source File: IndexRequestProcessorForTPFsTest.java From Server.Java with MIT License | 4 votes |
/** * Check that the type void:Dataset is returned as a URI and not as a * literal */ @Test public void shouldGiveVoidDatasetAsAURI() { final IDataSource datasource = new IDataSource() { @Override public String getDescription() { return "This is a dummy datasource"; }; @Override public IFragmentRequestParser getRequestParser() { return null; } @Override public IFragmentRequestProcessor getRequestProcessor() { return null; } @Override public String getTitle() { return "Dummy Dataource"; } @Override public void close() { // does nothing } }; final HashMap<String, IDataSource> datasources = new HashMap<String, IDataSource>(); datasources.put("dummy", datasource); final String baseUrl = "dummy"; final TestIndexRequestProcessor processor = new TestIndexRequestProcessor( baseUrl, datasources); final TriplePatternElementFactory<RDFNode, String, String> factory = new TriplePatternElementFactory<RDFNode, String, String>(); final ITriplePatternFragmentRequest<RDFNode, String, String> request = new TriplePatternFragmentRequestImpl<RDFNode, String, String>( null, "dummy", false, 1, factory.createUnspecifiedVariable(), factory.createUnspecifiedVariable(), factory.createUnspecifiedVariable()); final TestIndexRequestProcessor.TestWorker worker = processor .getTPFSpecificWorker(request); final ILinkedDataFragment fragment = worker.createRequestedFragment(); final StmtIterator iterator = fragment.getTriples(); final Collection<Statement> statements = new ArrayList<Statement>(); while (iterator.hasNext()) { statements.add(iterator.next()); } final Resource subject = ResourceFactory.createResource("dummy/dummy"); final Property predicate = ResourceFactory .createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); final Resource object = ResourceFactory .createResource("http://rdfs.org/ns/void#Dataset"); final Statement expected = ResourceFactory.createStatement(subject, predicate, object); Assert.assertTrue("triple not contained in model", statements.contains(expected)); processor.close(); }
Example 12
Source File: RDFUNITv.java From RDFUnit with Apache License 2.0 | 4 votes |
private static Resource resource(String local) { return ResourceFactory.createResource(namespace + local); }
Example 13
Source File: GERBIL.java From gerbil with GNU Affero General Public License v3.0 | 4 votes |
protected static final Resource resource(String local) { return ResourceFactory.createResource(uri + local); }
Example 14
Source File: SHACL_TEST.java From RDFUnit with Apache License 2.0 | 4 votes |
private static Resource resource(String local) { return ResourceFactory.createResource(namespace + local); }
Example 15
Source File: AlwaysFailingTestCase.java From RDFUnit with Apache License 2.0 | 4 votes |
public AlwaysFailingTestCase(ShapeTarget target){ this.target = target; this.element = ResourceFactory.createResource(AlwaysFailingTestCase.AlwaysFailingTestCasePrefix + JenaUUID.generate().asString()); this.sparqlWhere = "{ " + target.getPattern() + " FILTER NOT EXISTS {?this <http://example.org/some/non/existing/property> 9876545432} }"; }
Example 16
Source File: Application.java From Processor with Apache License 2.0 | 4 votes |
public Application(final Dataset dataset, final String endpointURI, final String graphStoreURI, final String quadStoreURI, final String authUser, final String authPwd, final MediaTypes mediaTypes, final Client client, final Integer maxGetRequestSize, final boolean preemptiveAuth, final LocationMapper locationMapper, final String ontologyURI, final String rulesString, boolean cacheSitemap) { super(dataset, endpointURI, graphStoreURI, quadStoreURI, authUser, authPwd, mediaTypes, client, maxGetRequestSize, preemptiveAuth); if (locationMapper == null) throw new IllegalArgumentException("LocationMapper be null"); if (ontologyURI == null) { if (log.isErrorEnabled()) log.error("Sitemap ontology URI (" + LDT.ontology.getURI() + ") not configured"); throw new ConfigurationException(LDT.ontology); } if (rulesString == null) { if (log.isErrorEnabled()) log.error("Sitemap Rules (" + AP.sitemapRules.getURI() + ") not configured"); throw new ConfigurationException(AP.sitemapRules); } this.ontologyURI = ontologyURI; this.cacheSitemap = cacheSitemap; if (dataset != null) service = new com.atomgraph.core.model.impl.dataset.ServiceImpl(dataset, mediaTypes); else { if (endpointURI == null) { if (log.isErrorEnabled()) log.error("SPARQL endpoint not configured ('{}' not set in web.xml)", SD.endpoint.getURI()); throw new ConfigurationException(SD.endpoint); } if (graphStoreURI == null) { if (log.isErrorEnabled()) log.error("Graph Store not configured ('{}' not set in web.xml)", A.graphStore.getURI()); throw new ConfigurationException(A.graphStore); } service = new com.atomgraph.core.model.impl.remote.ServiceImpl(client, mediaTypes, ResourceFactory.createResource(endpointURI), ResourceFactory.createResource(graphStoreURI), quadStoreURI != null ? ResourceFactory.createResource(quadStoreURI) : null, authUser, authPwd, maxGetRequestSize); } application = new ApplicationImpl(service, ResourceFactory.createResource(ontologyURI)); List<Rule> rules = Rule.parseRules(rulesString); OntModelSpec rulesSpec = new OntModelSpec(OntModelSpec.OWL_MEM); Reasoner reasoner = new GenericRuleReasoner(rules); //reasoner.setDerivationLogging(true); //reasoner.setParameter(ReasonerVocabulary.PROPtraceOn, Boolean.TRUE); rulesSpec.setReasoner(reasoner); this.ontModelSpec = rulesSpec; BuiltinPersonalities.model.add(Parameter.class, ParameterImpl.factory); BuiltinPersonalities.model.add(Template.class, TemplateImpl.factory); SPINModuleRegistry.get().init(); // needs to be called before any SPIN-related code ARQFactory.get().setUseCaches(false); // enabled caching leads to unexpected QueryBuilder behaviour DataManager dataManager = new DataManager(locationMapper, client, mediaTypes, preemptiveAuth); FileManager.setStdLocators(dataManager); FileManager.setGlobalFileManager(dataManager); if (log.isDebugEnabled()) log.debug("FileManager.get(): {}", FileManager.get()); OntDocumentManager.getInstance().setFileManager(dataManager); if (log.isDebugEnabled()) log.debug("OntDocumentManager.getInstance().getFileManager(): {}", OntDocumentManager.getInstance().getFileManager()); OntDocumentManager.getInstance().setCacheModels(cacheSitemap); // lets cache the ontologies FTW!! }
Example 17
Source File: ResultAnnotationImpl.java From RDFUnit with Apache License 2.0 | 4 votes |
public Builder(String elementUri, String propertyIri) { this(ResourceFactory.createResource(elementUri), ResourceFactory.createProperty(propertyIri)); }
Example 18
Source File: SystemTest.java From hypergraphql with Apache License 2.0 | 4 votes |
@Test void integration_test() { Model mainModel = ModelFactory.createDefaultModel(); final URL dbpediaContentUrl = getClass().getClassLoader().getResource("test_services/dbpedia.ttl"); if(dbpediaContentUrl != null) { mainModel.read(dbpediaContentUrl.toString(), "TTL"); } Model citiesModel = ModelFactory.createDefaultModel(); final URL citiesContentUrl = getClass().getClassLoader().getResource("test_services/cities.ttl"); if(citiesContentUrl != null) { citiesModel.read(citiesContentUrl.toString(), "TTL"); } Model expectedModel = ModelFactory.createDefaultModel(); expectedModel.add(mainModel).add(citiesModel); Dataset ds = DatasetFactory.createTxnMem(); ds.setDefaultModel(citiesModel); FusekiServer server = FusekiServer.create() .add("/ds", ds) .build() .start(); HGQLConfig externalConfig = HGQLConfig.fromClasspathConfig("test_services/externalconfig.json"); Controller externalController = new Controller(); externalController.start(externalConfig); HGQLConfig config = HGQLConfig.fromClasspathConfig("test_services/mainconfig.json"); Controller controller = new Controller(); controller.start(config); ObjectMapper mapper = new ObjectMapper(); ObjectNode bodyParam = mapper.createObjectNode(); bodyParam.put("query", "{\n" + " Person_GET {\n" + " _id\n" + " label\n" + " name\n" + " birthPlace {\n" + " _id\n" + " label\n" + " }\n" + " \n" + " }\n" + " City_GET {\n" + " _id\n" + " label}\n" + "}"); Model returnedModel = ModelFactory.createDefaultModel(); try { HttpResponse<InputStream> response = Unirest.post("http://localhost:8080/graphql") .header("Accept", "application/rdf+xml") .body(bodyParam.toString()) .asBinary(); returnedModel.read(response.getBody(), "RDF/XML"); } catch (UnirestException e) { e.printStackTrace(); } Resource res = ResourceFactory.createResource("http://hypergraphql.org/query"); Selector sel = new SelectorImpl(res, null, (Object) null); StmtIterator iterator = returnedModel.listStatements(sel); Set<Statement> statements = new HashSet<>(); while (iterator.hasNext()) { statements.add(iterator.nextStatement()); } for (Statement statement : statements) { returnedModel.remove(statement); } StmtIterator iterator2 = expectedModel.listStatements(); while (iterator2.hasNext()) { assertTrue(returnedModel.contains(iterator2.next())); } assertTrue(expectedModel.isIsomorphicWith(returnedModel)); externalController.stop(); controller.stop(); server.stop(); }
Example 19
Source File: RDFUNIT_SHACL_EXT.java From RDFUnit with Apache License 2.0 | 4 votes |
private static Resource resource(String local) { return ResourceFactory.createResource(namespace + local); }
Example 20
Source File: MappingCell.java From FCA-Map with GNU General Public License v3.0 | 4 votes |
public Resource getResource2() { if (m_resource2 == null) { return ResourceFactory.createResource(m_entity2); } return m_resource2; }