Created
March 11, 2016 13:53
-
-
Save mikedias/e169b67a62ccebff3be4 to your computer and use it in GitHub Desktop.
ScritpInputFormat for wikipedia RDF format
This file contains hidden or 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
/* | |
Parses the long_abstracts format: | |
<http://dbpedia.org/resource/Anarchism> <http://dbpedia.org/ontology/abstract> "Anarchism is a collection of movements and ideologies that ..."@en . | |
*/ | |
import org.openrdf.rio.* | |
import org.openrdf.rio.helpers.* | |
def parse(line, factory) { | |
def reader = new StringReader(line); | |
def model = new org.openrdf.model.impl.LinkedHashModel(); | |
def rdfParser = Rio.createParser(RDFFormat.TURTLE); | |
rdfParser.setRDFHandler(new StatementCollector(model)); | |
rdfParser.parse(reader, "http://dbpedia.org/"); | |
def v1; | |
model.forEach{ | |
def name = it.getSubject().stringValue().split("/").last(); | |
def text = it.getObject().stringValue(); | |
v1 = factory.vertex(name, "article"); | |
v1.property("article.name", name); | |
v1.property("article.text", text); | |
} | |
return v1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment