Skip to content

Commit

Permalink
Add entity URI only query
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Schultz committed Nov 16, 2020
1 parent 9b3faf9 commit d578218
Showing 1 changed file with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package org.silkframework.plugins.dataset.rdf.sparql

import java.util.concurrent.{ConcurrentLinkedQueue, LinkedBlockingQueue, TimeUnit}
import java.util.concurrent.{LinkedBlockingQueue, TimeUnit}
import java.util.logging.{Level, Logger}

import org.silkframework.dataset.rdf.{RdfNode, Resource, SparqlEndpoint, SparqlResults}
Expand Down Expand Up @@ -270,4 +270,42 @@ object ParallelEntityRetriever {
}
sparql.toString
}

/** Returns the entity URIs for a specific SPARQL restriction.
*
* @param subjectVar The variable name of the subject
* @param restriction A SPARQL restriction defined on the subject. Must have the same variable name as the subjectVar
* @param graphUri An optional graph URI
* @param useOrderBy Should the results be ordered by the subjectVar
*/
def entityUrisQuery(subjectVar: String,
restriction: SparqlRestriction,
graphUri: Option[String],
useOrderBy: Boolean): String = {
val varPrefix = "internal__vars"
//Select
val sparql = new StringBuilder
sparql append "SELECT DISTINCT "

sparql append "?" + subjectVar + " "

//Graph
for (graph <- graphUri if !graph.isEmpty) sparql append "FROM <" + graph + ">\n"

//Body
sparql append "WHERE {\n"

if (restriction.toSparql.isEmpty) {
sparql append "?" + subjectVar + " ?" + varPrefix + "_p ?" + varPrefix + "_o .\n"
} else {
sparql append restriction.toSparql + "\n"
}

sparql append "}" // END WHERE

if (useOrderBy) {
sparql append " ORDER BY " + "?" + subjectVar
}
sparql.toString
}
}

0 comments on commit d578218

Please sign in to comment.