Spaces:
Paused
Paused
Davide Fiocco commited on
Commit ·
5d92ad1
1
Parent(s): 948f8c5
Fix bugs with birthyear
Browse files- context.json +1 -1
- test_answers.py +9 -3
- utils.py +3 -3
context.json
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
{"info": "Sei Giuseppe Fiocco. Hai [AGE] anni. Sei nato
|
| 2 |
}
|
|
|
|
| 1 |
+
{"info": "Sei Giuseppe Fiocco. Hai [AGE] anni. Sei nato nel mese di maggio, nel [BIRTHYEAR]. Hai perso la memoria. Sei nato in Veneto. Abiti e vivi a Villafranca di Verona con Davide. L'indirizzo di casa è Corso Vittorio Emanuele 238. Ora siamo nell'anno [YEAR] e hai avuto un'encefalite virale a gennaio 2021. Hai perso la memoria a causa dell'encefalite. Pesi circa 85 kg, sei un po' ciccione. Sei alto 173 cm. Hai studiato Ingegneria elettronica a Padova. Davide è tuo figlio, ha [OTHERAGE] anni. I medici dicono che stai migliorando lentamente. Tua moglie Raffaella abita a Verona. Raffaella sta bene. Sei separato da Raffaella da circa 10 anni. Con Raffaella hai rapporti cordiali. Alessandro, Giovanni e Grazia sono i tuoi fratelli. I tuoi fratelli stanno bene. Davide era tuo padre e Gina era tua madre."
|
| 2 |
}
|
test_answers.py
CHANGED
|
@@ -16,7 +16,7 @@ context = get_context()
|
|
| 16 |
def test_name():
|
| 17 |
q = "Come mi chiamo?"
|
| 18 |
a = get_answer(q, context, nlp_qa)
|
| 19 |
-
assert a == "Giuseppe"
|
| 20 |
|
| 21 |
|
| 22 |
def test_age():
|
|
@@ -32,11 +32,17 @@ def test_weight():
|
|
| 32 |
|
| 33 |
|
| 34 |
def test_birthyear():
|
| 35 |
-
q = "
|
| 36 |
a = get_answer(q, context, nlp_qa)
|
| 37 |
assert a == "1952"
|
| 38 |
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
def test_year():
|
| 41 |
q = "In che anno siamo?"
|
| 42 |
a = get_answer(q, context, nlp_qa)
|
|
@@ -94,7 +100,7 @@ def test_family_3():
|
|
| 94 |
def test_family_4():
|
| 95 |
q = "Come sta Raffaella?"
|
| 96 |
a = get_answer(q, context, nlp_qa)
|
| 97 |
-
assert a
|
| 98 |
|
| 99 |
|
| 100 |
def test_family_5():
|
|
|
|
| 16 |
def test_name():
|
| 17 |
q = "Come mi chiamo?"
|
| 18 |
a = get_answer(q, context, nlp_qa)
|
| 19 |
+
assert a == "Giuseppe Fiocco"
|
| 20 |
|
| 21 |
|
| 22 |
def test_age():
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
def test_birthyear():
|
| 35 |
+
q = "In che anno sono nato?"
|
| 36 |
a = get_answer(q, context, nlp_qa)
|
| 37 |
assert a == "1952"
|
| 38 |
|
| 39 |
|
| 40 |
+
def test_birthmonth():
|
| 41 |
+
q = "In che mese sono nato?"
|
| 42 |
+
a = get_answer(q, context, nlp_qa)
|
| 43 |
+
assert a == "maggio"
|
| 44 |
+
|
| 45 |
+
|
| 46 |
def test_year():
|
| 47 |
q = "In che anno siamo?"
|
| 48 |
a = get_answer(q, context, nlp_qa)
|
|
|
|
| 100 |
def test_family_4():
|
| 101 |
q = "Come sta Raffaella?"
|
| 102 |
a = get_answer(q, context, nlp_qa)
|
| 103 |
+
assert a in "Raffaella sta bene"
|
| 104 |
|
| 105 |
|
| 106 |
def test_family_5():
|
utils.py
CHANGED
|
@@ -1,9 +1,6 @@
|
|
| 1 |
import datetime
|
| 2 |
import json
|
| 3 |
|
| 4 |
-
BIRTHYEAR = 1952
|
| 5 |
-
OTHERBIRTHYEAR = 1984
|
| 6 |
-
|
| 7 |
def get_answer(input, context, engine):
|
| 8 |
|
| 9 |
answer = engine({"question": input, "context": context})
|
|
@@ -13,12 +10,15 @@ def get_answer(input, context, engine):
|
|
| 13 |
|
| 14 |
def get_context():
|
| 15 |
|
|
|
|
|
|
|
| 16 |
now = datetime.datetime.now()
|
| 17 |
|
| 18 |
with open("context.json") as f:
|
| 19 |
context = (
|
| 20 |
json.load(f)["info"]
|
| 21 |
.replace("[YEAR]", str(now.year))
|
|
|
|
| 22 |
.replace("[AGE]", str(now.year - BIRTHYEAR))
|
| 23 |
.replace("[OTHERAGE]", str(now.year - OTHERBIRTHYEAR))
|
| 24 |
)
|
|
|
|
| 1 |
import datetime
|
| 2 |
import json
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
def get_answer(input, context, engine):
|
| 5 |
|
| 6 |
answer = engine({"question": input, "context": context})
|
|
|
|
| 10 |
|
| 11 |
def get_context():
|
| 12 |
|
| 13 |
+
BIRTHYEAR = 1952
|
| 14 |
+
OTHERBIRTHYEAR = 1984
|
| 15 |
now = datetime.datetime.now()
|
| 16 |
|
| 17 |
with open("context.json") as f:
|
| 18 |
context = (
|
| 19 |
json.load(f)["info"]
|
| 20 |
.replace("[YEAR]", str(now.year))
|
| 21 |
+
.replace("[BIRTHYEAR]", str(BIRTHYEAR))
|
| 22 |
.replace("[AGE]", str(now.year - BIRTHYEAR))
|
| 23 |
.replace("[OTHERAGE]", str(now.year - OTHERBIRTHYEAR))
|
| 24 |
)
|