I have an rdf file which looks somewhat like this (but it is actually larger):
@prefix skos-xl: <http://www.w3.org/2008/05/skos-xl#> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix adms: <http://www.w3.org/ns/adms#> .
@prefix esco: <http://data.europa.eu/esco/model#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix org: <http://www.w3.org/ns/org#> .
@prefix iso-thes: <http://purl.org/iso25964/skos-thes#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<http://data.europa.eu/esco/skill/238343b1-7b51-42b3-a9ed-cf24d3a236e7>
a skos:Concept , esco:MemberConcept , esco:Skill ;
esco:referenceLanguage "en"^^xsd:language ;
esco:skillReuseLevel <http://data.europa.eu/esco/skill-reuse-level/transversal> ;
esco:skillType <http://data.europa.eu/esco/skill-type/skill> ;
dct:description <http://data.europa.eu/esco/node-literal/447a21ac-f4e0-41e1-a478-1b7cd4c29af8> , <http://data.europa.eu/esco/node-literal/d9f98a36-44fb-4318-bfd9-6ac6b520b034> ;
iso-thes:status "released" ;
skos:altLabel "reconocer las carencias en competencias digitales"@es , "bearnaí maidir le cumas digiteach a aithint"@ga , "identificere manglende digitale kundskaber"@da , "digitale vaardigheidskloven identificeren"@nl , "detectar las deficiencias en competencias digitales"@es , "behoeften aan digitale vaardigheden herkennen"@nl , "παροχή υποστήριξης για την αντιμετώπιση ελλείψεων όσον αφορά την ψηφιακή ικανότητα"@el , "detectar las lagunas en competencias digitales"@es , "tunnistaa digitaalisten taitojen puutteet"@fi , "Lücken bei den IKT-Kompetenzen erkennen"@de ;
skos:broader <http://data.europa.eu/esco/skill/7e5147d1-60b1-4a68-804b-1f5cb0396b91> ;
skos:broaderTransitive <http://data.europa.eu/esco/skill/7e5147d1-60b1-4a68-804b-1f5cb0396b91> ;
skos:inScheme <http://data.europa.eu/esco/concept-scheme/skill-ict-groups> ;
skos:prefLabel "digitale vaardigheidskloven herkennen"@nl , "εντοπισμός ελλείψεων όσον αφορά την ψηφιακή ικανότητα"@el , [...] .
I have been reading a lot on the topic, but still I dont quite understand how I could convert this file to csv (or even JSON would do) with Java. So far I have been using the following script to extract all triples that exist in a graph and print them out in a console:
package semanticweb;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
getData();
}
static void getData(){
Model model = ModelFactory.createDefaultModel() ;
model.read("C:/Users/andri/eclipse-workspace/semanticweb/ict_skills_collection.ttl");
String queryString = "PREFIX skos-xl: <http://www.w3.org/2008/05/skos-xl#>" +
"PREFIX dct: <http://purl.org/dc/terms/>" +
"PREFIX adms: <http://www.w3.org/ns/adms#>" +
"PREFIX esco: <http://data.europa.eu/esco/model#>" +
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
"PREFIX org: <http://www.w3.org/ns/org#>"+
"PREFIX iso-thes: <http://purl.org/iso25964/skos-thes#>"+
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>" +
"PREFIX skos: <http://www.w3.org/2004/02/skos/core#>" +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" +
"PREFIX prov: <http://www.w3.org/ns/prov#>"+
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>" +
"SELECT *"+
"WHERE { ?s ?p ?o }";
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
try {
ResultSet results = qexec.execSelect();
while(results.hasNext()) {
QuerySolution qsol = results.nextSolution();
System.out.println(qsol.toString());
}
}
finally {
qexec.close();
}
}
}
The console output looks somewhat like this:
( ?p = <http://www.w3.org/2004/02/skos/core#prefLabel> ) ( ?o = "Defizite bei der digitalen Kompetenz ermitteln"@de ) ( ?s = <http://data.europa.eu/esco/skill/238343b1-7b51-42b3-a9ed-cf24d3a236e7> ) -> [Root]
( ?p = <http://www.w3.org/2004/02/skos/core#prefLabel> ) ( ?o = "identifikovat nedostatky v digitalnych kompetenciach"@sk ) ( ?s = <http://data.europa.eu/esco/skill/238343b1-7b51-42b3-a9ed-cf24d3a236e7> ) -> [Root]
( ?p = <http://www.w3.org/2004/02/skos/core#prefLabel> ) ( ?o = "identificar lacunas nas competencias digitais"@pt ) ( ?s = <http://data.europa.eu/esco/skill/238343b1-7b51-42b3-a9ed-cf24d3a236e7> ) -> [Root]
Does anyone know how I could proceed in converting this triple format to csv? Do I need to understand what these triples represent exactly in order to do this? I appreciate any help you can provide
You can use the something like:
public void writemodel(OntModel model) {
model.write(System.out, "JSON-LD");
model.write(System.out, "RDF/JSON");
}
To write your resultSet you can use
ResultSetFormatter.outputAsCSV(OutputStream, resultSet);
ResultSetFormatter.outputAsJSON(OutputStream, resultSet);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.