File size: 5,433 Bytes
0d3b770
 
09b648b
 
a14002e
 
 
 
0d3b770
e9b7721
 
85a22b9
212803e
0d3b770
a14002e
85a22b9
c63e932
618bce3
31ba554
a14002e
 
 
39fe403
a14002e
 
 
 
 
 
 
 
 
 
a463b89
618bce3
85a22b9
212803e
39fe403
212803e
 
 
 
 
 
 
 
 
85a22b9
98a2e37
1dc77a9
85a22b9
1dc77a9
39fe403
 
 
 
 
 
 
 
a463b89
 
a14002e
 
39fe403
a14002e
 
 
a463b89
a14002e
 
39fe403
a14002e
 
 
 
 
 
 
 
618bce3
a14002e
618bce3
 
a14002e
 
0d3b770
a14002e
 
0d3b770
 
deb32c3
22f968f
 
212803e
 
6998231
212803e
 
 
 
8eb51bf
 
 
 
 
 
 
 
0d3b770
 
22f968f
 
 
 
 
 
0d3b770
618bce3
 
0d3b770
a14002e
22f968f
618bce3
0d3b770
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from textblob import TextBlob
import gradio as gr
import os 
os.system("python -m textblob.download_corpora")
string_json={
    'control':'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN',
}
cont_list=list(string_json['control'])
def get_nouns(text):
    json_object={}
    sen_list=[]
    noun_list={}
    noun_box=[]
    blob = TextBlob(text)
    for sentence in blob.sentences:
        #print(sentence)
        sen_list.append(str(sentence))

    key_cnt=len(sen_list)
    cnt=0
    go=True
    a="Z"
    g="W"
    if go:            
        for ea in range(10):
            if go:            
                for b in range(50):
                    if go:
                        for c in range(50):
                            if go:
                                for d in range(50):
                                    if go:
                                        #for i,ea in enumerate(key_list):
                                        #json_object[sen_list[cnt]]=f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}'
                                        blob_n = TextBlob(sen_list[cnt])
                                        noun_p=blob_n.noun_phrases
                                        noun_box=[]
                                        
                                        for ea in blob_n.parse().split(" "):
                                            n=ea.split("/")
                                            if n[1] == "NN":
                                                noun_box.append(n[0])


                                        
                                        json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']={'sentence':sen_list[cnt],'noun_phrase':noun_p,'nouns':noun_box}
                                        
                                        for noun in noun_p:
                                            if noun in list(noun_list.keys()):
                                                noun_list[str(noun)].append(f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}')    
                                            else:
                                                noun_list[str(noun)]=[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']


                                        for nn in noun_box:
                                            if nn in list(noun_list.keys()):
                                                noun_list[str(nn)].append(f'{g}{cont_list[b]}{cont_list[c]}{cont_list[d]}')    
                                            else:
                                                noun_list[str(nn)]=[f'{g}{cont_list[b]}{cont_list[c]}{cont_list[d]}']
                                                
                                        if json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']=='ZNNN':
                                        #if json_object[sen_list[cnt]]=='ZNNN':
                                            #print ("Y")
                                            a="Y"
                                            g="V"
                                            b=0
                                            c=0
                                            d=0
                                        if json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']=='YNNN':
                                            #print("X")
                                            a="X"
                                            g="U"
                                            b=0
                                            c=0
                                            d=0                                   
                                        if cnt == key_cnt-1:
                                            print('done')
                                            go=False
                                            print(list(json_object.keys())[-1])
                                        else:
                                           
                                            cnt+=1

                                    
    
    #print(blob.tags)  # [('The', 'DT'), ('titular', 'JJ'),
    #  ('threat', 'NN'), ('of', 'IN'), ...]
    #print(blob.parse())
    #print(blob.noun_phrases)  # WordList(['titular threat', 'blob',
    #            'ultimate movie monster',
    #            'amoeba-like mass', ...])
    return json_object,noun_list
def find_query(query,sen,nouns):
    blob_f = TextBlob(query)
    noun_box={}
    noun_list=[]
    for ea in blob_f.parse().split(" "):
        n=ea.split("/")
        if n[1] == "NN":

            noun_list.append(n[0])
    nouns_l=list(nouns.keys())
    for nn in nouns_l:
        if nn in noun_list:
            if nn in noun_box:
                noun_box[str(nn)].append(nouns[nn])    
            else:
                noun_box[str(nn)]=[nouns[nn]]           
    return noun_box

with gr.Blocks() as app:
    inp = gr.Textbox(label="Paste Text",lines=10)
    btn = gr.Button("Load Document")
    with gr.Row():
        query=gr.Textbox(label="Search query")
        search_btn=gr.Button("Search")
    out_box=gr.Textbox(label="Results")
    with gr.Row():
        with gr.Column(scale=2):
            sen=gr.JSON(label="Sentences")
        with gr.Column(scale=1):
            nouns=gr.JSON(label="Nouns")
    search_btn.click(find_query,[query,sen,nouns],out_box)
    btn.click(get_nouns,inp,[sen,nouns])
app.launch()