コード例 #1
0
    def fire_action(self, action):
        model = self.model
        log.info("running action %s" % action)

        for res in RDF.SPARQLQuery(self.prefixes + '''
                SELECT ?light ?level
                WHERE {
                 <%s> room:lightLevel [room:light ?light; room:to ?level] .
                }''' % action).execute(model):
            self.do_lightlevel(res['light'].uri, res['level'])

        for res in RDF.SPARQLQuery(self.prefixes + '''
                SELECT ?command
                WHERE {
                 <%s> room:lightCommand ?command .
                }''' % action).execute(model):
            self.light_cmd(res['command'])

        for res in RDF.SPARQLQuery(self.prefixes + '''
                SELECT ?command
                WHERE {
                    <%s> room:execute ?command.
                }''' % action).execute(model):
            log.info("running %s" % str(res['command']))
            self.system_cmd(str(res['command']))
コード例 #2
0
    def fire(self, pred, obj):
        """
        fire actions with given pred/obj (both must be quoted n3)
        """
        try:
            self.load_rdf()
        except ValueError:
            log.debug("cannot search for actions")
            return

        model = self.model

        matches = 0
        for res in RDF.SPARQLQuery(self.prefixes + '''
                SELECT ?action
                WHERE {
                    [%s %s; room:triggers ?action] .
                }''' % (pred, obj)).execute(model):

            action = res['action'].uri
            matches = matches + 1
            self.fire_action(action)

        if matches == 0:
            log.debug("no commands matched %r %r" % (pred, obj))
        return matches
コード例 #3
0
def localEvaluation(modelSourceUri, queryString):
    model = RDF.Model()
    # TODO add possibility to explicitely set the content type and register things like namespaces = ttlParser.namespaces_seen()
    model.load(modelSourceUri)
    query = RDF.SPARQLQuery(queryString)
    result = query.execute(model)
    printQueryResults(result)
コード例 #4
0
 def _query(self, sparql):
     if isinstance(sparql, unicode):
         sparql = sparql.encode('utf8')
     query = RDF.SPARQLQuery(sparql)
     
     try:
         result = query.execute(self._model)
     except RDF.RedlandError, err:
         self.logger.error("Error in query:\n%s",sparql)
         raise QueryError(err)
コード例 #5
0
ファイル: redland_backend.py プロジェクト: lucag/sparrow
 def _query(self, sparql):
     # if isinstance(sparql, unicode):
     #     sparql = sparql.encode('utf8')
     query = RDF.SPARQLQuery(sparql)
     
     try:
         result = query.execute(self._model)
     except RDF.RedlandError as err:
         raise QueryError(err)
     return result
コード例 #6
0
ファイル: RDFModel.py プロジェクト: derwas/cso2rdf
 def sparql(self, query):
     query = RDF.SPARQLQuery(query)
     results = query.execute(self.model)
     return results
コード例 #7
0
 def query(self, qstr, base_uri=None):
     q = RDF.SPARQLQuery(qstr, base_uri=base_uri)
     results = q.execute(self._model)
     return results