Skip to content

Commit f35c414

Browse files
committed
static join enabled with pushStatic statement
1 parent a998c24 commit f35c414

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

src/main/antlr/While.g4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ ADAPT : 'adapt';
3434
MONITOR : 'monitor';
3535
TICK : 'tick';
3636
WINDOW : 'window';
37+
PUSH_STATIC: 'pushStatic';
3738
BREAKPOINT : 'breakpoint';
3839
SUPER : 'super';
3940
DESTROY : 'destroy';
@@ -151,6 +152,7 @@ statement : SKIP_S SEMI
151152
| RETURN expression SEMI # return_statement
152153
| fmu=expression DOT TICK OPARAN time=expression CPARAN SEMI # tick_statement
153154
| (declType = type)? target=expression ASS WINDOW OPARAN monitor=expression CPARAN SEMI # window_statement
155+
| PUSH_STATIC SEMI # pushStatic_statement
154156
| ((declType = type)? target=expression ASS)? expression DOT NAME OPARAN (expression (COMMA expression)*)? CPARAN SEMI # call_statement
155157
// TODO: allow new statements without assignment
156158
| (declType = type)? target=expression ASS NEW newType = type OPARAN (expression (COMMA expression)*)? CPARAN (MODELS owldescription = expression)? SEMI # create_statement

src/main/kotlin/no/uio/microobject/ast/Translate.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,11 @@ class Translate : WhileBaseVisitor<ProgramElement>() {
433433
return MonitorStmt(target, query, ll, ctx!!.start.line, target.getType())
434434
}
435435

436+
override fun visitPushStatic_statement(ctx: PushStatic_statementContext?): ProgramElement {
437+
return PushStaticStatement(ctx!!.start.line)
438+
}
439+
440+
436441
override fun visitWindow_statement(ctx: Window_statementContext?): ProgramElement {
437442
val target = visit(ctx!!.target) as Location
438443
if(ctx.declType != null) {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package no.uio.microobject.ast.stmt
2+
3+
import com.sksamuel.hoplite.ConfigLoader
4+
import no.uio.microobject.ast.*
5+
import no.uio.microobject.ast.expr.FALSEEXPR
6+
import no.uio.microobject.ast.expr.LiteralExpr
7+
import no.uio.microobject.ast.expr.TRUEEXPR
8+
import no.uio.microobject.runtime.*
9+
import no.uio.microobject.type.*
10+
import no.uio.microobject.data.TripleSettings
11+
import org.apache.jena.datatypes.xsd.XSDDatatype
12+
import java.io.File
13+
14+
import eu.larkc.csparql.core.engine.CsparqlQueryResultProxy
15+
import eu.larkc.csparql.common.RDFTuple
16+
17+
data class PushStaticStmt(val pos : Int = -1) : Statement {
18+
override fun toString(): String = "pushStatic()"
19+
override fun getRDF(): String {
20+
var s = "prog:stmt${this.hashCode()} rdf:type smol:PushStaticStmt.".trimIndent()
21+
return s
22+
}
23+
24+
25+
override fun eval(heapObj: Memory, stackFrame: StackEntry, interpreter: Interpreter): EvalResult {
26+
// fixed iri: prog:staticTable
27+
val namedIri = "${interpreter.settings.progPrefix}staticTable"
28+
29+
// add only staticTable
30+
val ts = TripleSettings(
31+
sources = hashMapOf("heap" to false, "staticTable" to true, "vocabularyFile" to false, "fmos" to false, "externalOntology" to false, "urlOntology" to false),
32+
guards = hashMapOf("heap" to true, "staticTable" to true),
33+
virtualization = hashMapOf("heap" to true, "staticTable" to true, "fmos" to true),
34+
jenaReasoner = interpreter.settings.reasoner,
35+
cachedModel = null
36+
)
37+
val sTableModel = interpreter.tripleManager.getModel(ts)
38+
interpreter.streamManager.putStaticNamedGraph(namedIri, sTableModel)
39+
40+
return EvalResult(null, emptyList())
41+
}
42+
43+
}

src/main/kotlin/no/uio/microobject/data/StreamManager.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ import java.util.Observer;
1616
import java.util.Observable
1717
import java.util.concurrent.ConcurrentHashMap
1818
import java.io.File
19+
import java.io.StringWriter
1920
import org.slf4j.Logger
2021
import org.slf4j.LoggerFactory
2122
import org.apache.log4j.BasicConfigurator
2223
import org.apache.log4j.Level
2324
import org.apache.log4j.Logger as Log4jLogger
2425
import org.apache.log4j.PropertyConfigurator
26+
import org.apache.jena.rdf.model.Model
2527
import kotlin.text.toLong
2628

2729
class ResultPusher(private val name: LiteralExpr, private val resultTable: MutableMap<LiteralExpr, RDFTable?>) : Observer {
@@ -154,5 +156,16 @@ class StreamManager(private val settings: Settings, val staticTable: StaticTable
154156
return queryWithPrefixes
155157
}
156158

159+
public fun putStaticNamedGraph(iri: String, model: Model) {
160+
if (!engineInitialized) initEngine()
161+
162+
// serialize the model (RDF/XML matches the engine's first attempt)
163+
val sw = StringWriter()
164+
model.write(sw, "RDF/XML")
165+
166+
// hand it to the C-SPARQL engine
167+
engine.putStaticNamedModel(iri, sw.toString())
168+
}
169+
157170
}
158171

0 commit comments

Comments
 (0)