예제 #1
0
#! /usr/bin/python

if __name__ == '__main__':
    from textProcessor.core.service import Service 
    
    #a = Service().populateGraph("The interpreter acts as a simple calculator: you can type an expression at it and it will write the value. Expression syntax is straightforward: the operators +, -, * and / work just like in most other languages (for example, Pascal or C); parentheses can be used for grouping. For example:")
    #a = Service().populateGraph("Blest with victory and peace, may the heav'n-rescued land Praise the Power that hath made and preserved us a nation! Then conquer we must, when our cause it is just,")
    
    a = Service().populateGraph("""ney mello sampaio sadksak sdsaljda
aksjdksa
askdjsakljd
ksadjksajd ksdjklsajd sakdjsakjda skasjdkasj
ney mello sampaio""")
    
    #print(a.getGraph())
    #print(a.getEdges())
    #print(a.getNGrams())

    ngrams = a.getNGrams()
    
    #for i in ngrams:
        #print(i)
    
    #print(ngrams.keys())
    #print(ngrams.values())
    items = ngrams.values()
    sorted(items)
    #print(sorted(items))
    
    for i in sorted(ngrams.items(), key=lambda x:x[1],reverse=True)[0:3]:
        print(i[0][0])
예제 #2
0
"""
import cgi
import json,sys

fs = cgi.FieldStorage()

print("Content-Type: application/json\n\n")
print()

scriptPath = "/var/www/textProcessor/"

sys.path.append(scriptPath)
from textProcessor.core.service import Service

processorResult = Service().populateGraph(fs["text"].value)

edges = []
for edge in processorResult.getEdges():
    edges.append({'vFrom':edge[0],'vTo':edge[1],'weight':processorResult.getEdges()[edge]})

"""
Sort the 3-grams and create an json-liked objects array
"""
ngrams = {}
total = 0
for n in sorted(processorResult.getNGrams().items(), key=lambda x:x[1],reverse=True):
    total += processorResult.getNGrams()[n[0]]
    if(len(ngrams) < 3):
        ngrams[n[0][0]+' '+n[0][1]+' '+n[0][2]]=processorResult.getNGrams()[n[0]]
#ngrams['Others'] = total