Exemplo n.º 1
0
    def getCategory(self, query, option, alltopicsandkeys):
        result = alltopicsandkeys
        outcome = {}
        merger = Merger()
        classifier = Classifier()
        # result = self.traversePages("setTopicandTerms",'topicmodel')
        classifier.init(result.topics, result.terms).MinKey(2)
        # classifier.load('articlemodel.json')
        classifier.load('classvectors.json')
        # queryvector.tojson('query')
        # print(queryvector.model['model'])
        outcome['categoriesconfidence'] = {}
        alreadymerged = 0
        for k, arr in result.terms.items():
            value = classifier.goodtopicscore(arr, query.lower())
            outcome['categoriesconfidence'][k] = value
            if option == 1:
                if value > 0 and not alreadymerged:
                    queryvector = self.docToclassvector(query, result)
                    classvectormodels = []
                    classvectormodels.append(classifier)
                    classvectormodels.append(queryvector)
                    classifier = merger.merge(classvectormodels)
                    alreadymerged = 1
                    # print("{} {}".format(k,value))
                value = 0
        classifier.tojson("classvectors")
        poutcome = classifier.predict('model', query).getTopics()
        k = Counter(poutcome)
        # Finding 3 highest values
        answer = k.most_common(3)
        categories = poutcome

        outcome['categoriestop3'] = answer
        outcome['categories'] = categories
        outcome['document'] = query
        outcome['categorieswordmatch'] = {}

        for k, v in classifier.termVectors.items():
            outcome['categorieswordmatch'][k] = str(v)
            # print(k)
            # print(v)

        # print(type(classifier.termVectors))
        # print(classifier.termVectors)
        return json.dumps(outcome)
Exemplo n.º 2
0
 def getclassificationmodel(self):
     classifier = Classifier()
     result = json.dumps(classifier.load("classvectors.json"))
     return result
Exemplo n.º 3
0
from classifier.gbc import GBC as Model
from classifier.gbc import Merger

model1 = Model()
model2 = Model()

model1.load("articlemodel.json")
model2.load("classvectors.json")
# model1.setweights()
# model2.setweights()
# model1.removeweights()
# model2.removeweights()

merger = Merger()
models = []
models.append(model1)
models.append(model2)
merger.merge(models)