Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanMattei committed Apr 28, 2017
2 parents 4d6793c + 96a3b45 commit 1f36ab7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,53 +66,55 @@ trait TypeAddition[Rdf <: RDF, DATASET]
} else Seq()
}

/* if there is not already some rdfs.label, foaf.lastName, foaf.familyName properties set,
* add a triple
* ?O rdfs.label ?LAB ,
* where ?LAB is computed from URI string of ?O
* NOTE: related to InstanceLabelsInference2#instanceLabel(), but here we actually add a triple,
* because we are in a callback for user edits
*
* TODO use also for plain HTML page annotation */
def addRDFSLabelValue() = {
val existingValues = (pgObjectt / rdfs.label).nodes
val existingValues2 = (pgObjectt / foaf.lastName).nodes
val existingValues3 = (pgObjectt / foaf.familyName).nodes
if (existingValues.isEmpty &&
existingValues2.isEmpty &&
existingValues3.isEmpty &&
( ! isAbsoluteURI(objectt.toString()) ||
objectt.toString().startsWith( instanceURIPrefix )
) ) {
if (isAbsoluteURI(objectt.toString()))
println("isAbsoluteURI " + objectt)
val labelTriple = makeTriple(
objectt, rdfs.label,
Literal( makeStringFromURI( objectt.toString() ) )
)
rdfStore.appendToGraph( dataset, makeGraphForSaving(), ops.makeGraph(Seq(labelTriple)))
}
}

def makeGraphForSaving() = {
graphURI.getOrElse(
foldNode(objectt)(
u => u,
bn => URI(""),
lit => URI("")))
}

////
//// body of function addType()

val result = if (objectt.isURI) {
val pgObjectt = PointedGraph[Rdf](objectt, graph)
val existingTypes = (pgObjectt / rdf.typ).nodes
if (existingTypes isEmpty) {
addRDFSLabelValue() // PENDING move out of the if() block
addRDFSLabelValue(objectt, graphURI) // PENDING move out of the if() block
addTypeValue()
} else Seq()
} else Seq()
result
}

/**
* if there is not already some rdfs.label, foaf.lastName, foaf.familyName properties set,
* add a triple
* ?O rdfs.label ?LAB ,
* where ?LAB is computed from URI string of ?O
* NOTES:
* - related to InstanceLabelsInference2#instanceLabel(), but here we actually add a triple,
* because we are in a callback for user edits
* - used also for plain HTML page annotation
*/
def addRDFSLabelValue(resource: Rdf#Node, graphURI: Option[Rdf#URI], graph: Rdf#Graph = allNamedGraph) = {
val pgObjectt = PointedGraph[Rdf](resource, graph)

val existingValues = (pgObjectt / rdfs.label).nodes
val existingValues2 = (pgObjectt / foaf.lastName).nodes
val existingValues3 = (pgObjectt / foaf.familyName).nodes
if (existingValues.isEmpty &&
existingValues2.isEmpty &&
existingValues3.isEmpty &&
(!isAbsoluteURI(resource.toString()) ||
resource.toString().startsWith(instanceURIPrefix))) {
if (isAbsoluteURI(resource.toString()))
println("isAbsoluteURI " + resource)
val labelTriple = makeTriple(
resource, rdfs.label,
Literal(makeStringFromURI(resource.toString())))
rdfStore.appendToGraph(dataset, makeGraphForSaving(resource, graphURI), ops.makeGraph(Seq(labelTriple)))
}
}

def makeGraphForSaving(objectt: Rdf#Node, graphURI: Option[Rdf#URI]) = {
graphURI.getOrElse(
foldNode(objectt)(
u => u,
bn => URI(""),
lit => URI("")))
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import deductions.runtime.utils.URIManagement
import deductions.runtime.utils.HTTPHelpers
import deductions.runtime.utils.HTTPrequest
import deductions.runtime.utils.RDFHelpers
import deductions.runtime.services.TypeAddition

/** */
trait RDFCacheDependencies[Rdf <: RDF, DATASET] {
Expand All @@ -45,7 +46,8 @@ trait RDFCacheAlgo[Rdf <: RDF, DATASET] extends RDFStoreLocalProvider[Rdf, DATAS
with BrowsableGraph[Rdf, DATASET]
with RDFHelpers[Rdf]
with URIManagement
with HTTPHelpers {
with HTTPHelpers
with TypeAddition[Rdf, DATASET] {

import scala.concurrent.ExecutionContext.Implicits.global

Expand Down Expand Up @@ -407,19 +409,27 @@ trait RDFCacheAlgo[Rdf <: RDF, DATASET] extends RDFStoreLocalProvider[Rdf, DATAS
}
}

/** needs Write transaction */
/** transaction inside (Write)
* TODO: graphURI should be obtained from the HTTP request, or else from user Id */
def pureHTMLwebPageAnnotateAsDocument(uri: Rdf#URI, request: HTTPrequest): Rdf#Graph = {
val newGraphWithUrl: Rdf#Graph = makeGraph(List(makeTriple(uri, rdf.typ, foaf.Document)))
wrapInTransaction { rdfStore.appendToGraph(dataset,
URI(makeAbsoluteURIForSaving(request.userId())),
newGraphWithUrl) }
val graphURI = URI(makeAbsoluteURIForSaving(request.userId()))
val newGraphWithUrl = makeGraph(List(makeTriple(uri, rdf.typ, foaf.Document)))
wrapInTransaction {
rdfStore.appendToGraph(
dataset,
graphURI,
newGraphWithUrl)
addRDFSLabelValue(uri, Some(graphURI))
}
println(s"pureHTMLwebPageAnnotateAsDocument: saved $newGraphWithUrl in graph <${makeAbsoluteURIForSaving(request.userId())}>")
val it = wrapInReadTransaction { find(allNamedGraph, uri, ANY, ANY) } . getOrElse( Iterator.empty )
val ret = newGraphWithUrl .
// NOTE: after user added triples, this way typeChange will not be triggered
union( makeGraph(it.toIterable))
println( s"pureHTMLwebPageAnnotateAsDocument: ret $ret" )
ret
val currentPageTriplesIterator = wrapInReadTransaction {
find(allNamedGraph, uri, ANY, ANY)
}.getOrElse(Iterator.empty) . toIterable
val result = newGraphWithUrl.
// NOTE: after user added triples, this way typeChange will not be triggered
union(makeGraph(currentPageTriplesIterator))
println(s"pureHTMLwebPageAnnotateAsDocument: ret $result")
result
}
}

0 comments on commit 1f36ab7

Please sign in to comment.