Skip to content
Snippets Groups Projects
Commit c124ae1f authored by miesma's avatar miesma
Browse files

add Sparql

parent ba21c81a
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/commons-codec-1.6.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/commons-csv-1.0.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/commons-lang3-3.3.2.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/httpclient-4.2.6.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/httpclient-cache-4.2.6.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/httpcore-4.2.5.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/jackson-annotations-2.3.0.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/jackson-core-2.3.3.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/jackson-databind-2.3.3.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/jcl-over-slf4j-1.7.6.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/jena-arq-2.13.0.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/jena-core-2.13.0.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/jena-iri-1.1.2.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/jena-tdb-1.1.2.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/jsonld-java-0.5.1.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/libthrift-0.9.2.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/log4j-1.2.17.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/slf4j-api-1.7.6.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/slf4j-log4j12-1.7.6.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/xercesImpl-2.11.0.jar"/>
<classpathentry kind="lib" path="C:/Users/miesma/workspace/Jena/apache-jena-2.13.0/lib/xml-apis-1.4.01.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Sparql</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
This diff is collapsed.
File added
import java.io.*;
import com.hp.hpl.jena.query.*;
//import com.hp.hpl.jena.rdf.model.*;
public class Sparql{
public static void main(String[] args) {
String service = "http://de.dbpedia.org/sparql";
String query ="PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>\n"
+ "PREFIX prop-de: <http://de.dbpedia.org/property/>\n"
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n"
+ "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n"
+ "SELECT DISTINCT (STR(?name) AS ?strname) ?stueck ?erstflug "
+ "?Flugzeug ?abstract ?thumbnail ?Hersteller ?NHersteller\n"
+ "WHERE { "
+ "?Flugzeug a dbpedia-owl:Aircraft.\n"
+ "?Flugzeug foaf:name ?name.\n"
+ "?Flugzeug prop-de:stckzahl ?stueck.\n"
+ "FILTER(?stueck<= \"9999999\"^^xsd:int).\n"
+ "?Flugzeug dbpedia-owl:abstract ?abstract.\n"
+ "OPTIONAL {?Flugzeug prop-de:erstflug ?erstflug.\n"
+ "FILTER(?erstflug < \"2050-12-30\"^^xsd:date).}\n"
+ "?Flugzeug dbpedia-owl:thumbnail ?thumbnail.\n"
+ "?Flugzeug dbpedia-owl:manufacturer ?Hersteller .\n"
+ "?Hersteller foaf:name ?NHersteller.\n"
+ "}";
QueryExecution e = QueryExecutionFactory.sparqlService(service, query);
ResultSet results = e.execSelect();
/*while (results.hasNext()){
QuerySolution s = results.nextSolution();
//System.out.println(s.toString());
Literal zahl = s.getLiteral("stueck");
RDFNode link = s.get("Flugzeug");
if (zahl.getValue() instanceof Integer) {
System.out.print("Flugzeug: "+link.toString()+" ");
System.out.println("Anzahl: "+zahl.getValue());
}
}
results = e.execSelect();*/
String xmlStr = ResultSetFormatter.asXMLString(results);
Writer writer = null;
try {
if (args.length > 0){
writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(args[0]), "utf-8"));
} else {
writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("aircraft.xml"), "utf-8"));
}
writer.write(xmlStr);
} catch (IOException ex) {
System.out.println(ex.getStackTrace());
} finally {
try {writer.close();} catch (Exception ex) {/*ignore*/}
}
//System.out.println(xmlStr);
e.close();
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment