コード例 #1
0
ファイル: SourceFile.py プロジェクト: sletort/askomics
    def load_data_from_file(self, fp, urlbase):
        """
        Load a locally created ttl file in the triplestore using http (with load_data(url)) or with the filename for Fuseki (with fuseki_load_data(fp.name)).

        :param fp: a file handle for the file to load
        :param urlbase:the base URL of current askomics instance. It is used to let triple stores access some askomics temporary ttl files using http.
        :return: a dictionnary with information on the success or failure of the operation
        """
        if not fp.closed:
            fp.flush(
            )  # This is required as otherwise, data might not be really written to the file before being sent to triplestore

        ql = QueryLauncher(self.settings, self.session)

        if self.is_defined('askomics.load_url'):
            urlbase = self.settings['askomics.load_url']

        url = urlbase + "/ttl/" + self.session[
            'username'] + '/' + os.path.basename(fp.name)

        data = {}
        data["status"] = "ok"
        try:
            if self.is_defined("askomics.file_upload_url"):
                queryResults = ql.upload_data(fp.name, self.graph)
            else:
                queryResults = ql.load_data(url, self.graph)
        except Exception as e:
            self.log.error(self._format_exception(e))
            raise e

        finally:
            os.remove(fp.name)

        return data
コード例 #2
0
ファイル: SourceFile.py プロジェクト: askomics/askomics
    def load_data_from_file(self, fp, urlbase):
        """
        Load a locally created ttl file in the triplestore using http (with load_data(url)) or with the filename for Fuseki (with fuseki_load_data(fp.name)).

        :param fp: a file handle for the file to load
        :param urlbase:the base URL of current askomics instance. It is used to let triple stores access some askomics temporary ttl files using http.
        :return: a dictionnary with information on the success or failure of the operation
        """
        if not fp.closed:
            fp.flush() # This is required as otherwise, data might not be really written to the file before being sent to triplestore

        ql = QueryLauncher(self.settings, self.session)

        if self.is_defined('askomics.load_url'):
            urlbase = self.settings['askomics.load_url']

        url = urlbase+"/ttl/"+ self.session['username'] + '/' + os.path.basename(fp.name)

        data = {}
        data["status"] = "ok"
        try:
            if self.is_defined("askomics.file_upload_url"):
                queryResults = ql.upload_data(fp.name, self.graph)
            else:
                queryResults = ql.load_data(url, self.graph)
        except Exception as e:
            self.log.error(self._format_exception(e))
            raise e

        finally:
            if self.settings['askomics.debug_ttl'] != 'true':
                os.remove(fp.name)

        return data
コード例 #3
0
ファイル: SourceFile.py プロジェクト: cbettemb/askomics
    def load_data_from_file(self, fp, urlbase):
        """
        Load a locally created ttl file in the triplestore using http (with load_data(url)) or with the filename for Fuseki (with fuseki_load_data(fp.name)).

        :param fp: a file handle for the file to load
        :param urlbase:the base URL of current askomics instance. It is used to let triple stores access some askomics temporary ttl files using http.
        :return: a dictionnary with information on the success or failure of the operation
        """
        if not fp.closed:
            fp.flush() # This is required as otherwise, data might not be really written to the file before being sent to triplestore

        sqb = SparqlQueryBuilder(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)
        graphName = "askomics:graph:" + self.name + '_' + self.timestamp
        self.metadatas['graphName'] = graphName
        ttlNamedGraph = "<" + graphName + "> " + "rdfg:subGraphOf" + " <" + self.get_param("askomics.graph") + "> ."
        sparqlHeader = sqb.header_sparql_config("")
        ql.insert_data(ttlNamedGraph, self.get_param("askomics.graph"), sparqlHeader)

        url = urlbase+"/ttl/"+os.path.basename(fp.name)
        self.log.debug(url)
        data = {}
        try:
            if self.is_defined("askomics.file_upload_url"):
                queryResults = ql.upload_data(fp.name, graphName)
                self.metadatas['server'] = queryResults.headers['Server']
                self.metadatas['loadDate'] = self.timestamp
            else:
                queryResults = ql.load_data(url, graphName)
                self.metadatas['server'] = queryResults.info()['server']
                self.metadatas['loadDate'] = self.timestamp
            data['status'] = 'ok'
        except Exception as e:
            self._format_exception(e, data=data)
        finally:
            if self.settings["askomics.debug"]:
                data['url'] = url
            else:
                os.remove(fp.name) # Everything ok, remove temp file

        self.get_metadatas()

        return data
コード例 #4
0
ファイル: SourceFile.py プロジェクト: afduarte/askomics
    def load_data_from_file(self, fp, urlbase):
        """
        Load a locally created ttl file in the triplestore using http (with load_data(url)) or with the filename for Fuseki (with fuseki_load_data(fp.name)).

        :param fp: a file handle for the file to load
        :param urlbase:the base URL of current askomics instance. It is used to let triple stores access some askomics temporary ttl files using http.
        :return: a dictionnary with information on the success or failure of the operation
        """
        if not fp.closed:
            fp.flush() # This is required as otherwise, data might not be really written to the file before being sent to triplestore

        sqb = SparqlQueryBuilder(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)
        graphName = "urn:sparql:" + self.name + '_' + self.timestamp
        self.metadatas['graphName'] = graphName
        ttlNamedGraph = "<" + graphName + "> " + "rdfg:subGraphOf" + " <" + self.get_param("askomics.graph") + "> ."
        sparqlHeader = sqb.header_sparql_config("")
        ql.insert_data(ttlNamedGraph, self.get_param("askomics.graph"), sparqlHeader)

        url = urlbase+"/ttl/"+os.path.basename(fp.name)
        self.log.debug(url)
        data = {}
        try:
            if self.is_defined("askomics.file_upload_url"):
                queryResults = ql.upload_data(fp.name, graphName)
                self.metadatas['server'] = queryResults.headers['Server']
                self.metadatas['loadDate'] = self.timestamp
            else:
                queryResults = ql.load_data(url, graphName)
                self.metadatas['server'] = queryResults.info()['server']
                self.metadatas['loadDate'] = self.timestamp
            data['status'] = 'ok'
        except Exception as e:
            self._format_exception(e, data=data)
        finally:
            if self.settings["askomics.debug"]:
                data['url'] = url
            else:
                os.remove(fp.name) # Everything ok, remove temp file

        self.get_metadatas()

        return data