Skip to content

Commit

Permalink
problem queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazzpirate committed Nov 13, 2023
1 parent 6c93755 commit 9ef0121
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/mmt-api/src/main/info/kwarc/mmt/api/ontology/ULO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,10 @@ object SPARQL {
sealed trait Object {
def toObjString : String
}
private case class StringO(s:String) extends Object {
def toObjString = "\"" + s + "\""
}

sealed trait SubjectT extends this.Object
case class Subject(s:String) extends SubjectT {
def toObjString = "<" + s + ">"
Expand Down Expand Up @@ -1014,6 +1018,7 @@ object SPARQL {
implicit def pathtosubject(p:Path): SubjectT = PathO(p)

implicit def classtoobject(p: ULOClass): Object = IriO(p.toIri)
implicit def stringtoobject(s:String): Object = StringO(s)
private case class SelectWhere(vars:List[String],where:SparqlQuery) extends SparqlQuery {
def queryString: String = s"SELECT ${vars.map("?" + _).mkString(" ")} WHERE { ${where.queryString} }"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import info.kwarc.mmt.api.{GlobalName, Path}
import info.kwarc.mmt.api.ontology.SPARQL.T
import info.kwarc.mmt.api.ontology.ULO
import info.kwarc.mmt.api.utils.{JSONArray, JSONNull, JSONObject, JSONString}
import info.kwarc.mmt.api.web.ServerResponse.{JsonResponse, ResourceResponse}
import info.kwarc.mmt.api.web.ServerResponse.{JsonResponse, ResourceResponse, TextResponse}
import info.kwarc.mmt.api.web.{ServerRequest, ServerResponse}
import info.kwarc.mmt.stex.STeXServer

Expand All @@ -24,6 +24,24 @@ trait QueryExtension { this : STeXServer =>
)):_*))
case Some("test") =>
JsonResponse(JSONArray(test.map(p => JSONString(p.toString)): _*))
case Some("problems") =>
import info.kwarc.mmt.api.ontology.SPARQL._
val query = (request.parsedQuery("path").map(Path.parse),request.parsedQuery("dimension")) match {
case (None,_) =>
val query = SELECT("path","objective_symbol","cognitive_dimension") WHERE (
HASTYPE(V("path"), ULO.problem) AND
T(V("path"), ULO.objective, V("w")) AND
T(V("w"), ULO.crossrefs, V("objective_symbol")) AND
T(V("w"), ULO.cognitiveDimension, V("cognitive_dimension"))
)
return JsonResponse(controller.depstore.query(query).getJson)
case (Some(path),None | Some("")) =>
SELECT("x") WHERE (HASTYPE(V("x"), ULO.problem) AND T(V("x"), ULO.objective, V("y")) AND T(V("y"), ULO.crossrefs, path))
case (Some(path),Some(dimen)) =>
SELECT("x") WHERE (HASTYPE(V("x"), ULO.problem) AND T(V("x"), ULO.objective, V("y")) AND T(V("y"), ULO.crossrefs, path) AND T(V("y"), ULO.cognitiveDimension, dimen))
}
val res = controller.depstore.query(query).getPaths.map(_.toString)
JsonResponse(JSONArray(res.map(JSONString): _*))
case _ =>
ResourceResponse("stex/queries.html")
}
Expand Down
2 changes: 1 addition & 1 deletion src/mmt-stex/src/info/kwarc/mmt/stex/xhtml/SHTMLNode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,8 @@ trait VollKIAnnotation extends SHTMLNode {
symbol.foreach { sym =>
sstate.foreach { state =>
findAncestor {
case e: SHTMLStatement if e.contentelem.isDefined => e
case p: SHTMLProblem if p.contentelem.isDefined => p
case e: SHTMLStatement if e.contentelem.isDefined => e
}.foreach { s =>
state.rel(new ULOStatement {
lazy val node = org.eclipse.rdf4j.model.util.Values.bnode()
Expand Down

0 comments on commit 9ef0121

Please sign in to comment.