コード例 #1
0
ファイル: query.py プロジェクト: AKSW/CSV2RDF-WIKI
class SMWQuery(object):
    def __init__(self):
        self.endpoint = SMWEndpoint()
        self.querygen = SMWQueryGenerator()

    def fetchResource(self, resourceId):
        rdfModel = self.endpoint.execute(self.querygen.getResourceQuery(resourceId))
        return rdfModel 

    def fetchResourceProperties(self, resourceId):
        resourceProperties = []
        resource = self.fetchResource(resourceId)
        resourcePropertiesQuery = RDF.Query(self.querygen.getResourcePropertiesQuery())
        for resourceProperty in resourcePropertiesQuery.execute(resource):
            resourceProperties.append("<%s>"%(resourceProperty['o']))
        return resourceProperties

    def fetchResourceDataset(self, resourceId):
        resource = self.fetchResource(resourceId)
        queryString = self.querygen.getResourceDatasetQuery()
        resourceDatasetQuery = RDF.Query(self.querygen.getResourceDatasetQuery())
        resourceDataset = "<%s>" %(str(resourceDatasetQuery.execute(resource).next()['o']),)
        return resourceDataset

    def fetchAllResourcesFromDataset(self, resourceId):
        datasetUri = self.fetchResourceDataset(resourceId)
        resourcesFromDatasetQuery = self.querygen.getResourceByDatasetUriQuery(datasetUri)
        return self.endpoint.execute(resourcesFromDatasetQuery)

    def fetchAllResourceIdsFromDataset(self, resourceId):
        resourceIds = []
        resources = self.fetchAllResourcesFromDataset(resourceId)
        resourceDistinctSubjectQuery = RDF.Query(self.querygen.getDistinctSubjectQuery())
        for resource in resourceDistinctSubjectQuery.execute(resources):
            resourceId = self.querygen._convertSparqlIdToResourceId(str(resource['s']).split("Csv2rdf-")[-1].lower())
            resourceIds.append(resourceId)
        return resourceIds
コード例 #2
0
ファイル: query.py プロジェクト: AKSW/CSV2RDF-WIKI
 def __init__(self):
     self.endpoint = SMWEndpoint()
     self.querygen = SMWQueryGenerator()