-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcompute.py
70 lines (47 loc) · 1.8 KB
/
compute.py
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
import pickle
from corpusdict import compute_basics_text
from get_num_determiners import get_num_determiners
from nlp.delusion_index.conceptnet5parser import get_concepts_from_files
from nlp.delusion_index.delusion_index import index_input
from nlp.delusion_index.delusion_queries import add_delusions, remove_delusions
from nlp.semantic_coherence.semantic_coherence import index_string
from nlp.syntactic_complexity.maxPhraseLength import max_phrase_length_text
def unpack_data(textarea):
return str(textarea.data)
def unpack_to_set(textarea):
return set(unpack_data(textarea).splitlines())
def number_of_words(textset):
return str(len(textset))
def calc_basics(text):
return compute_basics_text(text, 'all')
def calc_delusions(text):
default_delusion_categories = [
'time',
'self',
'surveillance',
'unfair',
'mind_control',
'alien'
]
remove_delusions()
add_delusions(default_delusion_categories)
concept_dict = get_concepts_from_files()
basics = calc_basics(text)
smart_ave_dict = index_input(basics, concept_dict)
return (smart_ave_dict)
def calc_coherence(text):
return (index_string(text))
def calc_determiners(text):
basics = calc_basics(text)
word_count = 0
for sentence in basics.words:
for w in sentence:
word_count += 1
return get_num_determiners(text) / float(word_count)
def calc_phrase_len(text):
return max_phrase_length_text(text) / 8.0
def calc_ml(coherence, determiners, phrase_len, a1, a2, a3, a4, a5, a6):
loaded_model = pickle.load(open('finalized_model.sav', 'rb'))
x = [min(coherence), determiners, phrase_len, a1, a2, a3, a4, a5, a6]
return "This passage has been determined to come from someone with " + \
str(loaded_model.predict(x)[0])