Exemplo n.º 1
0
    def search_predicates_object(self, pred, worksets):
        '''
           Search (predicate, object) pair in a workset
        '''
        sd = SparqlDao()
        workset  = ''
        for ws in worksets:
            workset += '<' + ws + '>'

        if "http" in pred:
            qry_string = FileOps().open('query/search_predicates_uri_ws.rq')
            qry_string = qry_string.format('<'+pred+'>', workset)
        else:
            qry_string = FileOps().open('query/search_predicates_literal_ws.rq')
            qry_string = qry_string.format('<'+pred+'>', workset)

        original = sd.autocomplete_sparql(self.endpoint, qry_string)

        count = 0
        preds = []
        for orig in original:
            count += int(orig[0])

        for data in original:
            preds.append({ "predicate": data[1], "weight": self._calculate_weight(data[0], count), "count": int(count)})

        return json.dumps(preds)
Exemplo n.º 2
0
    def search_predicates(self, searchterm):
        '''
          Find predicates associated with an object and calculates the weightings
          @todo: put this into named graph with time. 
          @todo: filter this for workset or non-workset. 
        '''
        original = []
        sd = SparqlDao()
        simil = Similarities()

        if "http" in searchterm:
            qry_string = FileOps().open('query/search_predicates_uri.rq')
            qry_string = qry_string.format('<'+searchterm+'>')
        else:
            qry_string = FileOps().open('query/search_predicates_literal.rq')
            qry_string = qry_string.format('"'+searchterm+'"')
        original = sd.autocomplete_sparql(self.endpoint, qry_string)

        count = 0
        preds = []
        for orig in original:
            count += int(orig[0])

        for data in original:
            preds.append({ "predicate": data[1], "weight": self._calculate_weight(data[0], count), "count":int(count)})

        return json.dumps(preds)
Exemplo n.º 3
0
    def join_graphs(self, graph):
        merged_data = []

        original = []
        sd = SparqlDao()
        
        #qry_string = FileOps().open('query/original_author.rq') 
        #qry_string = qry_string.format(graph)
        #original = sd.run_remote_sparql(self.endpoint, qry_string)

        #get the other graphs linked by VIAF
        qry_string = FileOps().open('query/walk_path_query.rq')
        qry_string = qry_string.format(graph)

        merged_data = sd.run_remote_sparql(self.endpoint, qry_string)

        link = []
        unlink = []
        for merge in merged_data:
            for orig in original:
                if orig[2] == merge[2] and orig[1] == merge[1]:
                    link.append(merge)

            if merge[1] not in link:
                unlink.append(merge)

        return json.dumps({"original":original,"link":link,"difference":self.deduplicate_data(unlink,link),"similarity":self.calculate_similarity_perc(link,original)})
Exemplo n.º 4
0
    def search_subject(self, searchterm):
        '''
          Find subjects associated with a predicate
          @todo: put this into named graph with time. 
          @todo: filter this for workset or non-workset. 
        '''
        original = []
        sd = SparqlDao()

        if "http" in searchterm:
            qry_string = FileOps().open('query/search_subjects_uri.rq')
            qry_string = qry_string.format('<'+searchterm+'>')
        else:
            qry_string = FileOps().open('query/search_subjects_literal.rq')
            qry_string = qry_string.format('"'+searchterm+'"')

        original = sd.autocomplete_sparql(self.endpoint, qry_string)
        terms  = []
        for data in original:
            terms.append({'id': data[0], 'value': data[1]})
        return json.dumps(terms)
Exemplo n.º 5
0
    def search_data_type(self, term, data_type):
        '''
           Perform substring search on data limited by a type and return JSON
        '''
        original = []
        sd = SparqlDao()

        qry_string = FileOps().open('query/search_string_type.rq')
        qry_string = qry_string.format(term, 'http://eeboo.oerc.ox.ac.uk/eeboo/' + data_type)

        original = sd.autocomplete_sparql(self.endpoint, qry_string)

        terms  = []
        for data in original:
            terms.append({'id': data[0], 'value': data[1]})

        return json.dumps(terms)
Exemplo n.º 6
0
    def search_data(self, term):
        '''
           Perform substring search on data and return JSON
        '''
        original = []
        sd = SparqlDao()

        qry_string = FileOps().open('query/search_string.rq')
        qry_string = qry_string.format(term)

        original = sd.autocomplete_sparql(self.endpoint, qry_string)

        terms  = []
        for data in original:
            terms.append({'id': data[0], 'value': data[1]})

        return json.dumps(terms)
Exemplo n.º 7
0
    def get_original(self, graphs):
        '''
          Gets the base graphs for the request
        '''
        original = []
        sd = SparqlDao()
        searchterm = ''
        for g in graphs:
            searchterm += '<' + str(g) + '>'

        qry_string = FileOps().open('query/original_author.rq')

        qry_string = qry_string.format(searchterm)


        original = sd.run_remote_sparql(self.endpoint, qry_string)
        return json.dumps(original)