| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| |
| |
| <title>Apache Jena - CSV PropertyTable - Get Started</title> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| |
| <link href="/css/bootstrap.min.css" rel="stylesheet" media="screen"> |
| <link href="/css/bootstrap-extension.css" rel="stylesheet" type="text/css"> |
| <link href="/css/jena.css" rel="stylesheet" type="text/css"> |
| <link rel="shortcut icon" href="/images/favicon.ico" /> |
| |
| <script src="https://code.jquery.com/jquery-2.2.4.min.js" |
| integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" |
| crossorigin="anonymous"></script> |
| <script src="/js/jena-navigation.js" type="text/javascript"></script> |
| <script src="/js/bootstrap.min.js" type="text/javascript"></script> |
| |
| <script src="/js/improve.js" type="text/javascript"></script> |
| |
| |
| </head> |
| |
| <body> |
| |
| <nav class="navbar navbar-default" role="navigation"> |
| <div class="container"> |
| <div class="navbar-header"> |
| <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse"> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| </button> |
| <a class="navbar-brand" href="/index.html"> |
| <img class="logo-menu" src="/images/jena-logo/jena-logo-notext-small.png" alt="jena logo">Apache Jena</a> |
| </div> |
| |
| <div class="collapse navbar-collapse navbar-ex1-collapse"> |
| <ul class="nav navbar-nav"> |
| <li id="homepage"><a href="/index.html"><span class="glyphicon glyphicon-home"></span> Home</a></li> |
| <li id="download"><a href="/download/index.cgi"><span class="glyphicon glyphicon-download-alt"></span> Download</a></li> |
| <li class="dropdown"> |
| <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-book"></span> Learn <b class="caret"></b></a> |
| <ul class="dropdown-menu"> |
| <li class="dropdown-header">Tutorials</li> |
| <li><a href="/tutorials/index.html">Overview</a></li> |
| <li><a href="/documentation/fuseki2/index.html">Fuseki Triplestore</a></li> |
| <li><a href="/documentation/notes/index.html">How-To's</a></li> |
| <li><a href="/documentation/query/manipulating_sparql_using_arq.html">Manipulating SPARQL using ARQ</a></li> |
| <li><a href="/tutorials/rdf_api.html">RDF core API tutorial</a></li> |
| <li><a href="/tutorials/sparql.html">SPARQL tutorial</a></li> |
| <li><a href="/tutorials/using_jena_with_eclipse.html">Using Jena with Eclipse</a></li> |
| <li class="divider"></li> |
| <li class="dropdown-header">References</li> |
| <li><a href="/documentation/index.html">Overview</a></li> |
| <li><a href="/documentation/query/index.html">ARQ (SPARQL)</a></li> |
| <li><a href="/documentation/assembler/index.html">Assembler</a></li> |
| <li><a href="/documentation/tools/index.html">Command-line tools</a></li> |
| <li><a href="/documentation/rdfs/">Data with RDFS Inferencing</a></li> |
| <li><a href="/documentation/geosparql/index.html">GeoSPARQL</a></li> |
| <li><a href="/documentation/inference/index.html">Inference API</a></li> |
| <li><a href="/documentation/javadoc.html">Javadoc</a></li> |
| <li><a href="/documentation/ontology/">Ontology API</a></li> |
| <li><a href="/documentation/permissions/index.html">Permissions</a></li> |
| <li><a href="/documentation/extras/querybuilder/index.html">Query Builder</a></li> |
| <li><a href="/documentation/rdf/index.html">RDF API</a></li> |
| <li><a href="/documentation/rdfconnection/">RDF Connection - SPARQL API</a></li> |
| <li><a href="/documentation/io/">RDF I/O</a></li> |
| <li><a href="/documentation/rdfstar/index.html">RDF-star</a></li> |
| <li><a href="/documentation/shacl/index.html">SHACL</a></li> |
| <li><a href="/documentation/shex/index.html">ShEx</a></li> |
| <li><a href="/documentation/jdbc/index.html">SPARQL over JDBC</a></li> |
| <li><a href="/documentation/tdb/index.html">TDB</a></li> |
| <li><a href="/documentation/tdb2/index.html">TDB2</a></li> |
| <li><a href="/documentation/query/text-query.html">Text Search</a></li> |
| </ul> |
| </li> |
| |
| <li class="drop down"> |
| <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-book"></span> Javadoc <b class="caret"></b></a> |
| <ul class="dropdown-menu"> |
| <li><a href="/documentation/javadoc.html">All Javadoc</a></li> |
| <li><a href="/documentation/javadoc/arq/">ARQ</a></li> |
| <li><a href="/documentation/javadoc_elephas.html">Elephas</a></li> |
| <li><a href="/documentation/javadoc/fuseki2/">Fuseki</a></li> |
| <li><a href="/documentation/javadoc/geosparql/">GeoSPARQL</a></li> |
| <li><a href="/documentation/javadoc/jdbc/">JDBC</a></li> |
| <li><a href="/documentation/javadoc/jena/">Jena Core</a></li> |
| <li><a href="/documentation/javadoc/permissions/">Permissions</a></li> |
| <li><a href="/documentation/javadoc/extras/querybuilder/">Query Builder</a></li> |
| <li><a href="/documentation/javadoc/shacl/">SHACL</a></li> |
| <li><a href="/documentation/javadoc/tdb/">TDB</a></li> |
| <li><a href="/documentation/javadoc/text/">Text Search</a></li> |
| </ul> |
| </li> |
| |
| <li id="ask"><a href="/help_and_support/index.html"><span class="glyphicon glyphicon-question-sign"></span> Ask</a></li> |
| |
| <li class="dropdown"> |
| <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-bullhorn"></span> Get involved <b class="caret"></b></a> |
| <ul class="dropdown-menu"> |
| <li><a href="/getting_involved/index.html">Contribute</a></li> |
| <li><a href="/help_and_support/bugs_and_suggestions.html">Report a bug</a></li> |
| <li class="divider"></li> |
| <li class="dropdown-header">Project</li> |
| <li><a href="/about_jena/about.html">About Jena</a></li> |
| <li><a href="/about_jena/architecture.html">Architecture</a></li> |
| <li><a href="/about_jena/citing.html">Citing</a></li> |
| <li><a href="/about_jena/team.html">Project team</a></li> |
| <li><a href="/about_jena/contributions.html">Related projects</a></li> |
| <li><a href="/about_jena/roadmap.html">Roadmap</a></li> |
| <li class="divider"></li> |
| <li class="dropdown-header">ASF</li> |
| <li><a href="http://www.apache.org/">Apache Software Foundation</a></li> |
| <li><a href="http://www.apache.org/foundation/sponsorship.html">Become a Sponsor</a></li> |
| <li><a href="http://www.apache.org/licenses/LICENSE-2.0">License</a></li> |
| <li><a href="http://www.apache.org/security/">Security</a></li> |
| <li><a href="http://www.apache.org/foundation/thanks.html">Thanks</a></li> |
| </ul> |
| </li> |
| |
| |
| |
| |
| <li id="edit"><a href="https://github.com/apache/jena-site/edit/main/source/documentation/archive/csv/get_started.md" title="Edit this page on GitHub"><span class="glyphicon glyphicon-pencil"></span> Edit this page</a></li> |
| </ul> |
| </div> |
| </div> |
| </nav> |
| |
| |
| <div class="container"> |
| <div class="row"> |
| <div class="col-md-12"> |
| <div id="breadcrumbs"> |
| |
|
|
|
|
|
|
|
|
|
|
|
|
| <ol class="breadcrumb">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| <li><a href='/documentation'>DOCUMENTATION</a></li>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| <li><a href='/documentation/archive'>ARCHIVE</a></li>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| <li><a href='/documentation/archive/csv'>CSV</a></li>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| <li class="active">GET STARTED</li>
|
|
|
|
|
|
|
|
|
| </ol>
|
|
|
|
|
|
|
| |
| |
| </div> |
| <h1 class="title">CSV PropertyTable - Get Started</h1> |
| |
| <h2 id="using-csv-propertytable-with-apache-maven">Using CSV PropertyTable with Apache Maven</h2> |
| <p>See <a href="/download/maven.html">“Using Jena with Apache Maven”</a> for full details.</p> |
| <pre><code><dependency> |
| <groupId>org.apache.jena</groupId> |
| <artifactId>jena-csv</artifactId> |
| <version>X.Y.Z</version> |
| </dependency> |
| </code></pre> |
| <h2 id="using-csv-propertytable-from-java-through-the-api">Using CSV PropertyTable from Java through the API</h2> |
| <p>In order to switch on CSV PropertyTable, it’s required to register <code>LangCSV</code> into <a href="/documentation/io/">Jena RIOT</a>, through a simple method call:</p> |
| <pre><code>import org.apache.jena.propertytable.lang.CSV2RDF; |
| ... |
| CSV2RDF.init() ; |
| </code></pre> |
| <p>It’s a static method call of registration, which needs to be run just one time for an application before using CSV PropertyTable (e.g. during the initialization phase).</p> |
| <p>Once registered, CSV PropertyTable provides 2 ways for the users to play with (i.e. GraphCSV and RIOT):</p> |
| <h3 id="graphcsv">GraphCSV</h3> |
| <p><a href="https://github.com/apache/jena/tree/main/jena-csv/src/main/java/org/apache/jena/propertytable/graph/GraphCSV.java">GraphCSV</a> wrappers a CSV file as a Graph, which makes a Model for SPARQL query:</p> |
| <pre><code>Model model = ModelFactory.createModelForGraph(new GraphCSV("data.csv")) ; |
| QueryExecution qExec = QueryExecutionFactory.create(query, model) ; |
| </code></pre> |
| <p>or for multiple CSV files and/or other RDF data:</p> |
| <pre><code>Model csv1 = ModelFactory.createModelForGraph(new GraphCSV("data1.csv")) ; |
| Model csv2 = ModelFactory.createModelForGraph(new GraphCSV("data2.csv")) ; |
| Model other = ModelFactory.createModelForGraph(otherGraph) ; |
| Dataset dataset = ... ; |
| dataset.addNamedModel("http://example/table1", csv1) ; |
| dataset.addNamedModel("http://example/table2", csv2) ; |
| dataset.addNamedModel("http://example/other", other) ; |
| ... normal SPARQL execution ... |
| </code></pre> |
| <p>You can also find the full examples from <a href="https://github.com/apache/jena/tree/main/jena-csv/src/test/java/org/apache/jena/propertytable/graph/GraphCSVTest.java">GraphCSVTest</a>.</p> |
| <p>In short, for Jena ARQ, a CSV table is actually a Graph (i.e. GraphCSV), without any differences from other types of Graphs when using it from the Jena ARQ API.</p> |
| <h3 id="riot">RIOT</h3> |
| <p>When LangCSV is registered into RIOT, CSV PropertyTable adds a new RDF syntax of ‘.csv’ with the content type of “text/csv”. |
| You can read “.csv” files into Model following the standard RIOT usages:</p> |
| <pre><code>// Usage 1: Direct reading through Model |
| Model model_1 = ModelFactory.createDefaultModel() |
| model.read("test.csv") ; |
| |
| // Usage 2: Reading using RDFDataMgr |
| Model model_2 = RDFDataMgr.loadModel("test.csv") ; |
| </code></pre> |
| <p>For more information, see <a href="/documentation/io/rdf-input.html">Reading RDF in Apache Jena</a>.</p> |
| <p>Note that, the requirements for the CSV files are listed in the documentation of <a href="design.html">Design</a>. CSV PropertyTable only supports <strong>single-Value</strong>, <strong>regular-Shaped</strong>, <strong>table-headed</strong> and <strong>UTF-8-encoded</strong> CSV files (<strong>NOT</strong> Microsoft Excel files).</p> |
| <h2 id="command-line-tool">Command Line Tool</h2> |
| <p><a href="https://github.com/apache/jena/tree/main/jena-csv/src/main/java/riotcmd/csv2rdf.java">csv2rdf</a> is a tool for direct transforming from CSV to the formatted RDF syntax of N-Triples. |
| The script calls the <code>csv2rdf</code> java program in the <code>riotcmd</code> package in this way:</p> |
| <pre><code>java -cp ... riotcmdx.csv2rdf inputFile ... |
| </code></pre> |
| <p>It transforms the CSV <code>inputFile</code> into N-Triples. For example,</p> |
| <pre><code>java -cp ... riotcmdx.csv2rdf src/test/resources/test.csv |
| </code></pre> |
| <p>The script reuses <a href="../io/index.html">Common framework for running RIOT parsers</a>, |
| so that it also accepts the same arguments |
| (type <code>"riot --help"</code> to get command line reminders) from |
| <a href="/documentation/io/#command-line-tools">RIOT Command line tools</a>:</p> |
| <ul> |
| <li><code>--validate</code>: Checking mode: same as <code>--strict --sink --check=true</code></li> |
| <li><code>--check=true/false</code>: Run with checking of literals and IRIs either on or off.</li> |
| <li><code>--sink</code>: No output of triples or quads in the standard output (i.e. <code>System.out</code>).</li> |
| <li><code>--time</code>: Output timing information.</li> |
| </ul> |
| |
| |
| </div> |
| </div> |
| |
| </div> |
| |
| <footer class="footer"> |
| <div class="container" style="font-size:80%" > |
| <p> |
| Copyright © 2011–2022 The Apache Software Foundation, Licensed under the |
| <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>. |
| </p> |
| <p> |
| Apache Jena, Jena, the Apache Jena project logo, Apache and the Apache feather logos are trademarks of |
| The Apache Software Foundation. |
| <br/> |
| <a href="https://privacy.apache.org/policies/privacy-policy-public.html" |
| >Apache Software Foundation Privacy Policy</a>. |
| </p> |
| </div> |
| </footer> |
| |
| |
| <script type="text/javascript"> |
| var link = $('a[href="' + this.location.pathname + '"]'); |
| if (link != undefined) |
| link.parents('li,ul').addClass('active'); |
| </script> |
| |
| </body> |
| </html> |