org.apache.jena.rdf.model.impl.StatementImpl Java Examples

The following examples show how to use org.apache.jena.rdf.model.impl.StatementImpl. 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: ShaclValidator.java    From rdflint with MIT License 5 votes vote down vote up
@Override
public void prepareValidationResource(Map<String, List<Triple>> fileTripleSet) {
  final ModelCom model = new ModelCom(new GraphMem());
  fileTripleSet.forEach((k, v) -> {
    v.forEach(t -> {
      model.add(StatementImpl.toStatement(t, model));
    });
  });
  result = ValidationUtil.validateModel(model, model, true)
      .getModel().getGraph();
}
 
Example #2
Source File: PropertySurfaceForms.java    From NLIWOD with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException {

		PROPERTY_SURFACE_FORMS = DIRECTORY + "property_surface_forms.ttl";

		// create an empty model
		Model inputModel = ModelFactory.createDefaultModel();

		// use the FileManager to find the input file
		InputStream in = FileManager.get().open(DBPEDIA_PROPERTY_FILE);
		if (in == null) {
			throw new IllegalArgumentException("File: " + DBPEDIA_PROPERTY_FILE + " not found");
		}

		// read the RDF/XML file
		inputModel.read(in, null, "N-TRIPLE");
		inputModel.write(System.out);

		Model outputModel = ModelFactory.createDefaultModel();
		QueryExecution qExec = QueryExecutionFactory
				.create("SELECT ?s  ?label WHERE{?s a <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property>."
						+ " ?s <http://www.w3.org/2000/01/rdf-schema#label> ?label. }", inputModel);
		ResultSet rs = qExec.execSelect();
		System.out.println(qExec);
		while (rs.hasNext()) {
			QuerySolution qs = rs.next();
			Resource uri = qs.get("?s").asResource();
			RDFNode label = qs.get("?label");
			StatementImpl s = new StatementImpl(uri, RDFS.label, label);
			outputModel.add(s);

		}

		qExec.close();

		FileOutputStream outputFile = new FileOutputStream(PROPERTY_SURFACE_FORMS);
		RDFDataMgr.write(outputFile, outputModel, RDFFormat.NTRIPLES);
	}
 
Example #3
Source File: ClassSurfaceForms.java    From NLIWOD with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException {

		CLASS_SURFACE_FORMS = DIRECTORY + "class_surface_forms.ttl";

		// create an empty model
		Model inputModel = ModelFactory.createDefaultModel();

		// use the FileManager to find the input file
		InputStream in = FileManager.get().open(DBPEDIA_CLASSE_FILE);
		if (in == null) {
			throw new IllegalArgumentException("File: " + DBPEDIA_CLASSE_FILE + " not found");
		}

		// read the RDF/XML file
		inputModel.read(in, null, "N-TRIPLE");

		Model outputModel = ModelFactory.createDefaultModel();
		QueryExecution qExec = QueryExecutionFactory
				.create("SELECT ?s ?label WHERE{?s a <http://www.w3.org/2002/07/owl#Class>."
						+ " ?s <http://www.w3.org/2000/01/rdf-schema#label> ?label. "
						+ "FILTER (lang(?label) = \"en\")}", inputModel);
		ResultSet rs = qExec.execSelect();
		while (rs.hasNext()) {
			QuerySolution qs = rs.next();
			Resource uri = qs.get("?s").asResource();
			RDFNode label = qs.get("?label");
			StatementImpl s = new StatementImpl(uri, RDFS.label, label);
			outputModel.add(s);

		}

		qExec.close();

		FileOutputStream outputFile = new FileOutputStream(CLASS_SURFACE_FORMS);
		RDFDataMgr.write(outputFile, outputModel, RDFFormat.NTRIPLES);

	}
 
Example #4
Source File: DBpediaToWikiId.java    From gerbil with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * The Wikipedia Id or -1 if the Id couldn't be retrieved.
 * 
 * FIXME The method throws an exception for "http://DBpedia.org/resource/Origin_of_the_name_"Empire_State"". this
 * might be happen because of the quotes inside the URI.
 * 
 * @param dbpediaUri
 * @return
 */
@Deprecated
public static int getIdFromDBpedia(String dbpediaUri) {
    int id = -1;
    ParameterizedSparqlString query = new ParameterizedSparqlString(
            "SELECT ?id WHERE { ?dbpedia dbo:wikiPageID ?id .}", prefixes);
    query.setIri("dbpedia", dbpediaUri);
    QueryExecution qexec = null;
    try {
        qexec = QueryExecutionFactory.create(query.asQuery(),
                model);
    } catch (QueryParseException e) {
        LOGGER.error("Got a bad dbpediaUri \"" + dbpediaUri
                + "\" which couldn't be parse inside of a SPARQL query. Returning -1.", e);
        return id;
    }
    ResultSet result = qexec.execSelect();
    if (result.hasNext()) {
        id = result.next().get("id").asLiteral().getInt();
        return id;
    }
    qexec = QueryExecutionFactory.sparqlService(
            "http://dbpedia.org/sparql", query.asQuery());
    result = qexec.execSelect();
    if (result.hasNext()) {
        id = result.next().get("id").asLiteral().getInt();
        model.add(new StatementImpl(model.createResource(dbpediaUri), model
                .createProperty("http://dbpedia.org/ontology/wikiPageID"),
                model.createTypedLiteral(id)));
        return id;
    }

    model.add(new StatementImpl(model.createResource(dbpediaUri), model
            .createProperty("http://dbpedia.org/ontology/wikiPageID"),
            model.createTypedLiteral(id)));
    return id;
}