Created
July 24, 2013 04:57
-
-
Save anonymous/6068164 to your computer and use it in GitHub Desktop.
Code to generate a CSV file from RDF document. Each row represents an individual with all its property values in columns. The separator is ";"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.hp.hpl.jena.rdf.model.ModelFactory | |
import scala.collection.JavaConversions._ | |
val m = ModelFactory.createOntologyModel | |
m.read("****INPUT****","N3") | |
val properties = (m.listDatatypeProperties.toList ++ m.listObjectProperties) | |
val individualRows = m.listIndividuals.toList.map(i => | |
i.getURI + ";" + properties. | |
map(p => i.listPropertyValues(p).toList.mkString(",")).mkString(";") | |
) | |
val printer = new java.io.PrintWriter("out1.csv") | |
printer.println("URI;" + properties.map(_.getURI).mkString(";")) | |
printer.println(individualRows.mkString("\n")) | |
printer.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i'm the author