Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More consolidation of the r2rml/virtual knowledge graph subsystem (sp…
…arqlify / ontop)
- Loading branch information
Showing
4 changed files
with
133 additions
and
82 deletions.
There are no files selected for viewing
32 changes: 4 additions & 28 deletions
32
...n/src/main/scala/net/sansa_stack/rdf/common/partition/core/RdfPartitionImportExport.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,22 @@ | ||
package net.sansa_stack.rdf.common.partition.core | ||
|
||
import org.aksw.r2rml.jena.arq.lib.R2rmlLib | ||
import org.aksw.r2rml.jena.domain.api.TriplesMap | ||
import org.aksw.r2rml.jena.vocab.RR | ||
import org.apache.jena.rdf.model.{Model, ModelFactory} | ||
|
||
import net.sansa_stack.rdf.common.partition.r2rml.R2rmlUtils | ||
|
||
import scala.collection.JavaConverters._ | ||
import org.apache.jena.rdf.model.Model | ||
|
||
/** | ||
* @author Lorenz Buehmann | ||
*/ | ||
object RdfPartitionImportExport { | ||
|
||
/** | ||
* Exports the RDF partition states as R2RML. | ||
* | ||
* @param partitioner the RDF partitioner | ||
* @param partitions the RDF partition states | ||
* @param explodeLanguageTags if `true` a separate mapping/TriplesMap will be created for each language tag, | ||
* otherwise a mapping to a column for the language tag represented by | ||
* `rr:langColumn` property will be used (note, this is an extension of R2RML) | ||
* @return the model containing the RDF partition states as as R2RML syntax | ||
*/ | ||
def exportAsR2RML(partitioner: RdfPartitioner[RdfPartitionStateDefault], | ||
partitions: Seq[RdfPartitionStateDefault], | ||
explodeLanguageTags: Boolean = false): Model = { | ||
// put all triple maps into a single model | ||
val model = ModelFactory.createDefaultModel() | ||
|
||
R2rmlUtils.createR2rmlMappings(partitioner, partitions, model, explodeLanguageTags) | ||
|
||
model | ||
} | ||
|
||
/** | ||
* Imports the RDF partition states as `TriplesMap` from the given RDF data model. | ||
* | ||
* @param model the model | ||
* @return the RDF partition states as `TriplesMap` | ||
*/ | ||
def importFromR2RML(model: Model): Seq[TriplesMap] = { | ||
model.listResourcesWithProperty(RR.logicalTable).mapWith(_.as(classOf[TriplesMap])).asScala.toSeq | ||
import collection.JavaConverters._ | ||
R2rmlLib.streamTriplesMaps(model).iterator().asScala.toSeq | ||
} | ||
} |
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
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
41 changes: 41 additions & 0 deletions
41
sansa-rdf/sansa-rdf-spark/src/main/scala/net/sansa_stack/rdf/spark/utils/PartitionLib.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package net.sansa_stack.rdf.spark.utils | ||
|
||
import net.sansa_stack.rdf.common.partition.core.{RdfPartitionStateDefault, RdfPartitioner} | ||
import net.sansa_stack.rdf.common.partition.r2rml.R2rmlUtils | ||
import net.sansa_stack.rdf.spark.partition.core.{BlankNodeStrategy, SQLUtils} | ||
import org.aksw.sparqlify.core.sql.common.serialization.SqlEscaperBacktick | ||
import org.apache.jena.rdf.model.{Model, ModelFactory} | ||
|
||
/** | ||
* @author Lorenz Buehmann | ||
*/ | ||
object PartitionLib { | ||
/** | ||
* Exports the RDF partition states as R2RML. | ||
* Uses table name and sql escaping configuration suitable for spark. | ||
* | ||
* @param partitioner the RDF partitioner | ||
* @param partitions the RDF partition states | ||
* @param explodeLanguageTags if `true` a separate mapping/TriplesMap will be created for each language tag, | ||
* otherwise a mapping to a column for the language tag represented by | ||
* `rr:langColumn` property will be used (note, this is an extension of R2RML) | ||
* @return the model containing the RDF partition states as as R2RML syntax | ||
*/ | ||
def exportAsR2RML(partitioner: RdfPartitioner[RdfPartitionStateDefault], | ||
partitions: Seq[RdfPartitionStateDefault], | ||
explodeLanguageTags: Boolean = false): Model = { | ||
// put all triple maps into a single model | ||
val model = ModelFactory.createDefaultModel() | ||
|
||
partitions.flatMap(partition => | ||
R2rmlUtils.createR2rmlMappings( | ||
partitioner, | ||
partition, | ||
p => SQLUtils.createTableName(p, BlankNodeStrategy.Table), | ||
new SqlEscaperBacktick, | ||
model, explodeLanguageTags) | ||
) | ||
|
||
model | ||
} | ||
} |