Exemplo n.º 1
0
    def stream(self, data):

        print('\nThe following request in RDF format was passed:')
        print(data)

        identification, theDate, suri, puri, ouri = extract.getValues(data)

        print('\nSURI, PURI and OURI are:')
        print(suri)
        print(puri)
        print(ouri)
        print('\n')

        # sid, pid, oid = self.uriToId(suri, puri, ouri)
        sid, pid, oid = mapping.convert(suri, puri, ouri)

        # required for passing it to compute_mincostflow
        sid, pid, oid = np.array([sid]), np.array([pid]), np.array([oid])

        t1 = time()

        print('\nTheir corresponding IDs are:')
        print(sid)
        print(pid)
        print(oid)
        print('\n')

        log.info('Computing KL for triple')
        with warnings.catch_warnings():
            try:
                warnings.simplefilter("ignore")

                # compute klinker
                scores, paths, rpaths, times = self.compute_klinker(
                    self.G, sid, pid, oid)

                normalizedScore = normalization.score(scores[0])

                log.info(
                    'KLinker computation complete. Time taken: {:.2f} secs.\n'.
                    format(time() - t1))
                result = '<http://swc2017.aksw.org/task2/dataset/s-' + str(
                    identification
                ) + '> <http://swc2017.aksw.org/hasTruthValue>\"' + str(
                    normalizedScore
                ) + '\"<http://www.w3.org/2001/XMLSchema#double> .'
                print('The result in RDF format is:')
                print(result)

            except MemoryError:
                print('\nA MemoryError is successfully caught.')
                result = 'MemoryError'

        return result
Exemplo n.º 2
0
    def stream(self, data, args=None):

        print('\nThe following request in RDF format was passed:')
        print(data)

        identification, theDate, suri, puri, ouri = extract.getValues(data)

        print('\nSURI, PURI and OURI are:')
        print(suri)
        print(puri)
        print(ouri)
        print('\n')

        # sid, pid, oid = self.uriToId(suri, puri, ouri)
        sid, pid, oid = mapping.convert(suri, puri, ouri)

        # required for passing it to compute_mincostflow
        sid, pid, oid = np.array([sid]), np.array([pid]), np.array([oid])

        t1 = time()

        print('\nTheir corresponding IDs are:')
        print(sid)
        print(pid)
        print(oid)
        print('\n')

        log.info('Computing Predpath for triple')
        int_sid = int(sid)
        int_pid = int(pid)
        int_oid = int(oid)

        print("The subject id is: %s " % int_sid)
        print("The predicate id is: %s" % int_pid)
        print("The object id is: %s" % int_oid)

        # Creating a dataframe
        data = {
            'sid': [int_sid],
            'pid': [int_pid],
            'oid': [int_oid],
            'class': [0]
        }

        #__________________test________________________
        dfObj = pd.DataFrame(data)
        test_spo_df = dfObj.dropna(axis=0,
                                   subset=['sid', 'pid', 'oid', 'class'])

        test_model_pkl = open("./output/trained_pra_model.pkl", "rb")
        test_model = pkl.load(test_model_pkl)

        test_features_pkl = open("./output/pra_features_file.pkl", "rb")
        test_features = pkl.load(test_features_pkl)
        with warnings.catch_warnings():
            try:
                warnings.simplefilter("ignore")

                # pra_predict() function is used to predict the triple's veracity
                array_value = pra_predict(self.G, test_features, test_model,
                                          test_spo_df)  # test
                val = str(array_value)[1:-1]
                log.info(
                    'Predpath computation complete. Time taken: {:.2f} secs.\n'
                    .format(time() - t1))
                result = '<http://swc2017.aksw.org/task2/dataset/s-' + str(
                    identification
                ) + '> <http://swc2017.aksw.org/hasTruthValue>\"' + str(
                    val) + '\"<http://www.w3.org/2001/XMLSchema#double> .'
                print('The result in RDF format is:')
                print(result)

            except MemoryError:
                print('\nA MemoryError is successfully caught.')
                result = 'MemoryError'

        return result