parent
5cc6b45673
commit
cecd4c0f12
8 changed files with 518 additions and 350 deletions
@ -0,0 +1,6 @@ |
|||||||
|
import streamlit as st |
||||||
|
|
||||||
|
|
||||||
|
st.set_page_config( |
||||||
|
page_title="Malå", |
||||||
|
) |
||||||
@ -1,95 +0,0 @@ |
|||||||
import streamlit as st |
|
||||||
from identify_person import find_person, verify |
|
||||||
from _arango import arango |
|
||||||
import re |
|
||||||
from time import time |
|
||||||
|
|
||||||
|
|
||||||
@st.cache_data() |
|
||||||
def get_persons(): |
|
||||||
return list(arango.db.collection('persons').all()) |
|
||||||
|
|
||||||
@st.cache_data() |
|
||||||
def get_other_persons(): |
|
||||||
q = 'for doc in persons filter doc.other == true return doc' |
|
||||||
return [i for i in db.aql.execute(q)] |
|
||||||
|
|
||||||
@st.cache_data() |
|
||||||
def get_suggestions(person): |
|
||||||
print('Finding person', person) |
|
||||||
with st.spinner('Hämtar data...'): |
|
||||||
answers = find_person(person) |
|
||||||
print('ANSWERS',answers) |
|
||||||
return answers |
|
||||||
|
|
||||||
db = arango.db |
|
||||||
|
|
||||||
if 'persons' not in st.session_state: |
|
||||||
st.session_state.persons = get_persons() |
|
||||||
st.session_state.persons_names = [i['name'] for i in st.session_state.persons] |
|
||||||
st.session_state.persons_dict = {i['name']: i['_key'] for i in st.session_state.persons} |
|
||||||
if 'other_persons' not in st.session_state: |
|
||||||
st.session_state.other_persons = get_other_persons() |
|
||||||
|
|
||||||
if 'radio1' in st.session_state: |
|
||||||
del st.session_state['radio1'] |
|
||||||
|
|
||||||
if 'suggestions' not in st.session_state: |
|
||||||
st.session_state.suggestions = [] |
|
||||||
|
|
||||||
# If suggestions are all used up |
|
||||||
|
|
||||||
|
|
||||||
if st.session_state.suggestions == []: |
|
||||||
st.session_state.other_person = st.session_state.other_persons.pop(0) |
|
||||||
suggestions = get_suggestions(st.session_state.other_person) |
|
||||||
print(suggestions) |
|
||||||
if suggestions == None: |
|
||||||
st.rerun() |
|
||||||
else: |
|
||||||
st.session_state.suggestions = suggestions |
|
||||||
|
|
||||||
st.session_state.suggestion = st.session_state.suggestions.pop(0) |
|
||||||
|
|
||||||
answer, person_in_arango, interrogation_doc, other_person, found_person, found_person_info, person = st.session_state.suggestion |
|
||||||
|
|
||||||
text = interrogation_doc['text'] |
|
||||||
answer = answer.replace('\n', ' ') |
|
||||||
st.markdown(f'Är :blue[{other_person}] samma som :blue[{found_person}]?') |
|
||||||
st.write(f'(från förhör med {interrogation_doc["person"]})') |
|
||||||
if 'JA' in answer: |
|
||||||
st.markdown(f'🤖\n:green[{answer}]') |
|
||||||
radio_index = 0 |
|
||||||
elif 'NEJ' in answer: |
|
||||||
radio_index = 1 |
|
||||||
st.markdown(f'🤖\n:red[{answer}]') |
|
||||||
else: |
|
||||||
radio_index = None |
|
||||||
st.markdown(f'🤖\n{answer}') |
|
||||||
|
|
||||||
with st.form('Form'): |
|
||||||
with st.expander('Mer information'): |
|
||||||
text = re.sub(r'\n\n+', '\n', text) |
|
||||||
text = text.replace('\n', '<br>') |
|
||||||
st.markdown(f'##### Förhöret:\n{text}', unsafe_allow_html=True) |
|
||||||
|
|
||||||
st.markdown(f'##### {found_person}:') |
|
||||||
st.markdown(found_person_info, unsafe_allow_html=True) |
|
||||||
|
|
||||||
user_choice = st.radio('', ('Ja', 'Nej', 'Vet ej'), key=time(), index=radio_index) |
|
||||||
other_choice = st.selectbox('Välj alla som stämmer', st.session_state.persons_names, placeholder='Sök en annan', index=None, key=time() + 'multiselect') |
|
||||||
|
|
||||||
st.form_submit_button('Nästa') |
|
||||||
|
|
||||||
if other_choice: |
|
||||||
person_in_arango = db.collection('persons').get(st.session_state.persons_dict[other_choice]) |
|
||||||
print('Yes', person, person_in_arango, text, db) |
|
||||||
#verify('Yes', person, person_in_arango, text, db) |
|
||||||
elif user_choice == 'Ja': |
|
||||||
print(('Yes', person, person_in_arango)) |
|
||||||
#verify('Yes', person, person_in_arango, text, db) |
|
||||||
elif user_choice == 'Nej': |
|
||||||
pass |
|
||||||
elif user_choice == 'Vet ej': |
|
||||||
pass |
|
||||||
#verify('Unknown', person, person_in_arango, text, db) |
|
||||||
@ -1,11 +1,23 @@ |
|||||||
def print_green(text): |
def print_green(*args): |
||||||
|
text = '' |
||||||
|
for arg in args: |
||||||
|
text += str(arg) + ' ' |
||||||
print(f"\033[92m{text}\033[0m") |
print(f"\033[92m{text}\033[0m") |
||||||
|
|
||||||
def print_red(text): |
def print_red(*args): |
||||||
|
text = '' |
||||||
|
for arg in args: |
||||||
|
text += str(arg) + ' ' |
||||||
print(f"\033[91m{text}\033[0m") |
print(f"\033[91m{text}\033[0m") |
||||||
|
|
||||||
def print_yellow(text): |
def print_yellow(*args): |
||||||
|
text = '' |
||||||
|
for arg in args: |
||||||
|
text += str(arg) + ' ' |
||||||
print(f"\033[93m{text}\033[0m") |
print(f"\033[93m{text}\033[0m") |
||||||
|
|
||||||
def print_blue(text): |
def print_blue(*args): |
||||||
|
text = '' |
||||||
|
for arg in args: |
||||||
|
text += str(arg) + ' ' |
||||||
print(f"\033[94m{text}\033[0m") |
print(f"\033[94m{text}\033[0m") |
||||||
@ -0,0 +1,33 @@ |
|||||||
|
import networkx as nx |
||||||
|
from _arango import arango |
||||||
|
import random |
||||||
|
from print_color import * |
||||||
|
import json |
||||||
|
import datetime |
||||||
|
|
||||||
|
# Create a new directed graph |
||||||
|
G = nx.DiGraph() |
||||||
|
|
||||||
|
q = "for doc in interrogations return doc" |
||||||
|
interrogations = list(arango.db.aql.execute(q)) |
||||||
|
|
||||||
|
|
||||||
|
for interrogation in interrogations: |
||||||
|
if not 'mentioned_persons' in interrogation: |
||||||
|
continue |
||||||
|
person_key = interrogation['person_id'].split('/')[1] |
||||||
|
mentioned_persons = interrogation["mentioned_persons"] |
||||||
|
for mentioned_person in mentioned_persons: |
||||||
|
G.add_edge( |
||||||
|
person_key, |
||||||
|
mentioned_person, |
||||||
|
label=interrogation["_key"], |
||||||
|
) |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Write the graph to a GEXF file |
||||||
|
current_time = datetime.datetime.now().strftime("%H-%M-%S") |
||||||
|
filename = f"output_files/mentions_{current_time}.gexf" |
||||||
|
nx.write_gexf(G, filename) |
||||||
|
|
||||||
@ -0,0 +1,67 @@ |
|||||||
|
import networkx as nx |
||||||
|
from _arango import arango |
||||||
|
import random |
||||||
|
from print_color import * |
||||||
|
import json |
||||||
|
import datetime |
||||||
|
|
||||||
|
# Create a new directed graph |
||||||
|
G = nx.DiGraph() |
||||||
|
|
||||||
|
q = "for doc in rumors filter doc.sexual_content != null return doc" |
||||||
|
rumors = list(arango.db.aql.execute(q)) |
||||||
|
|
||||||
|
not_heard_from = 0 |
||||||
|
for rumor in rumors: |
||||||
|
interrogation = arango.db.collection("interrogations").get(rumor["_key"]) |
||||||
|
if not rumor["sexual_summary"]: |
||||||
|
rumor["sexual_summary"] = "" |
||||||
|
|
||||||
|
# From person |
||||||
|
if 'heard_from' not in rumor or not rumor['heard_from']: |
||||||
|
not_heard_from += 1 |
||||||
|
rumor["heard_from"] = "Unknown_" + str(random.randint(1, 1000000)) |
||||||
|
|
||||||
|
# To person |
||||||
|
if "person_id" in interrogation: |
||||||
|
rumor["heard_person"] = interrogation["person"] |
||||||
|
if 'class' not in rumor: |
||||||
|
rumor['class'] = 'Unknown' |
||||||
|
if 'class_description' not in rumor: |
||||||
|
rumor['class_description'] = 'Unknown' |
||||||
|
# Add an edge to the graph with 'sexual_summary' as an attribute |
||||||
|
G.add_edge( |
||||||
|
rumor["heard_from"], |
||||||
|
rumor["heard_person"], |
||||||
|
label=rumor["_key"], |
||||||
|
content=rumor["sexual_summary"], |
||||||
|
class_=rumor["class"], |
||||||
|
class_description=rumor["class_description"], |
||||||
|
) |
||||||
|
|
||||||
|
|
||||||
|
heards_froms = set([rumor["heard_from"] for rumor in rumors]) |
||||||
|
heard_persons = set([rumor["heard_person"] for rumor in rumors]) |
||||||
|
all_nodes = list(heards_froms.union(heard_persons)) |
||||||
|
|
||||||
|
q = "for doc in persons filter doc.name in @all_nodes return doc" |
||||||
|
persons = list(arango.db.aql.execute(q, bind_vars={"all_nodes": all_nodes})) |
||||||
|
|
||||||
|
|
||||||
|
G.add_nodes_from( |
||||||
|
[ |
||||||
|
( |
||||||
|
person["name"], |
||||||
|
{"_key": json.dumps(person["_key"]), "info": json.dumps(person["info"])}, |
||||||
|
) |
||||||
|
for person in persons |
||||||
|
] |
||||||
|
) |
||||||
|
|
||||||
|
# Write the graph to a GEXF file |
||||||
|
current_time = datetime.datetime.now().strftime("%H-%M-%S") |
||||||
|
filename = f"output_files/rumors_{current_time}.gexf" |
||||||
|
nx.write_gexf(G, filename) |
||||||
|
|
||||||
|
print(len(rumors)) |
||||||
|
print(not_heard_from) |
||||||
Loading…
Reference in new issue