ln2sql icon indicating copy to clipboard operation
ln2sql copied to clipboard

Nonetype object Not Iterable on using thesaurus

Open Pushkalb opened this issue 6 years ago • 9 comments

Hi, I tried to use thesaurus, but I'm getting an issue saying "argument of type 'NoneType' is not iterable". Could anyone help on this? Thanks!

Pushkalb avatar Feb 26 '19 21:02 Pushkalb

some word‘s equivalences is none but original code have code like “sth in equivalences“, so you just need to add a condition to ensure this part code doesnt execute when equivalence is none

sakuranew avatar May 06 '19 06:05 sakuranew

I had this problem it seems that self.database_object.get_table_by_name(table_name).equivalences in parser.py:711&806 can be NoneType.

You can avoid the bugs by adding these two lines above:

if self.database_object.get_table_by_name(table_name).equivalences is None:
    continue

Why is this variable sometimes NoneType?

  • I have no idea.

vlevieux avatar May 22 '19 19:05 vlevieux

It solution is interesting .... i'll try it

El 22 may. 2019 2:35 PM, "vlevieux" [email protected] escribió:

I had this problem it seems that self.database_object.get_ table_by_name(table_name).equivalences in parser.py:711&806 can be NoneType.

You can avoid the bugs by adding these two lines above:

if self.database_object.get_table_by_name(table_name).equivalences is None: continue

Why is this variable sometimes NoneType?

  • I have no idea.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/FerreroJeremy/ln2sql/issues/56?email_source=notifications&email_token=AJCKPKIAAH5OSGUBLO3ULXLPWWOADA5CNFSM4G2MUJE2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWACSNI#issuecomment-494938421, or mute the thread https://github.com/notifications/unsubscribe-auth/AJCKPKMAIVHXAV6V7GZORWLPWWOADANCNFSM4G2MUJEQ .

-- El contenido de este mensaje y sus anexos son únicamente para el uso del destinatario y pueden contener información  clasificada o reservada. Si usted no es el destinatario intencional, absténgase de cualquier uso, difusión, distribución o copia de esta comunicación.

Heernandez avatar May 22 '19 20:05 Heernandez

It seems to be a problem by reading the thesaurus dictionary. In the paper, they indicated:

Ainsi si la table regroupant les informations des étudiants a par exemple pour nom ETUD_UNIV_01, et qu'aucun synonyme n'a donc été automatiquement ajouté à ce nom de table, l'utilisateur pourra rentrer manuellement le mot étudiant comme synonyme [...].

Thus, if the table containing the students' information has, for example, the name ETUD_UNIV_01, and no synonyms have been automatically added to this table name, the user can manually enter the word student as a synonym [...].

Then I tried to get the table chambre when I ask with azertyuiop (random word) to try this feature.

Then I added these lines in the thesaurus dictionary:

chambre|1
(noun)|azertyuiop|randomword

I ran the following command:

python -m ln2sql.main -d database_store/hotel.sql -l lang_store/english.csv -t thesaurus_store\th_english.dat -j output.json -i "What are the azertyuiop with nbLit greater than 3?"

The result is: (it's correct)

SELECT *
FROM chambre
WHERE chambre.nbLit > '3';

I noticed with the following lines in the thesaurus dictionary doesn't work. You need to add another value as above.

chambre|1
(noun)|azertyuiop

I need to figure out the way they retrieve values. Why does it return NoneType? Why doesn't single synonym work?

vlevieux avatar May 22 '19 22:05 vlevieux

just let the equivalences =[] rather than Nonetype when initialize the database object

sakuranew avatar May 23 '19 05:05 sakuranew

I had this problem it seems that self.database_object.get_table_by_name(table_name).equivalences in parser.py:711&806 can be NoneType.

You can avoid the bugs by adding these two lines above:

if self.database_object.get_table_by_name(table_name).equivalences is None:
    continue

Why is this variable sometimes NoneType?

  • I have no idea.

After which line of code(please put the statement) should we place the if condition?

bdonepudi97 avatar Mar 23 '20 14:03 bdonepudi97

I had this problem it seems that self.database_object.get_table_by_name(table_name).equivalences in parser.py:711&806 can be NoneType. You can avoid the bugs by adding these two lines above:

if self.database_object.get_table_by_name(table_name).equivalences is None:
    continue

Why is this variable sometimes NoneType?

  • I have no idea.

After which line of code(please put the statement) should we place the if condition?

i tried adding after 709 and 805. However the output seems to be different before and after. Please refer to below screenshot

image

So, Instead of continuing when the self.database_object.get_table_by_name(table_name).equivalences is None, i have tried setting it to empty List.

if self.database_object.get_table_by_name(table_name).equivalences is None:
      self.database_object.get_table_by_name(table_name).equivalences = []

Here is the expected output: image

rakesh160 avatar Apr 09 '20 12:04 rakesh160

It seems to be a problem by reading the thesaurus dictionary. In the paper, they indicated:

Ainsi si la table regroupant les informations des étudiants a par exemple pour nom ETUD_UNIV_01, et qu'aucun synonyme n'a donc été automatiquement ajouté à ce nom de table, l'utilisateur pourra rentrer manuellement le mot étudiant comme synonyme [...].

Thus, if the table containing the students' information has, for example, the name ETUD_UNIV_01, and no synonyms have been automatically added to this table name, the user can manually enter the word student as a synonym [...].

Then I tried to get the table chambre when I ask with azertyuiop (random word) to try this feature.

Then I added these lines in the thesaurus dictionary:

chambre|1
(noun)|azertyuiop|randomword

I ran the following command:

python -m ln2sql.main -d database_store/hotel.sql -l lang_store/english.csv -t thesaurus_store\th_english.dat -j output.json -i "What are the azertyuiop with nbLit greater than 3?"

The result is: (it's correct)

SELECT *
FROM chambre
WHERE chambre.nbLit > '3';

I noticed with the following lines in the thesaurus dictionary doesn't work. You need to add another value as above.

chambre|1
(noun)|azertyuiop

I need to figure out the way they retrieve values. Why does it return NoneType? Why doesn't single synonym work?

Seems like even the single word works but we have to end it with a pipe as below

chambre|1
(noun)|azertyuiop|

instead of

chambre|1
(noun)|azertyuiop

rakesh160 avatar Apr 09 '20 12:04 rakesh160

It seems to be a problem by reading the thesaurus dictionary. In the paper, they indicated:

Ainsi si la table regroupant les informations des étudiants a par exemple pour nom ETUD_UNIV_01, et qu'aucun synonyme n'a donc été automatiquement ajouté à ce nom de table, l'utilisateur pourra rentrer manuellement le mot étudiant comme synonyme [...].

Thus, if the table containing the students' information has, for example, the name ETUD_UNIV_01, and no synonyms have been automatically added to this table name, the user can manually enter the word student as a synonym [...].

Then I tried to get the table chambre when I ask with azertyuiop (random word) to try this feature.

Then I added these lines in the thesaurus dictionary:

chambre|1
(noun)|azertyuiop|randomword

I ran the following command:

python -m ln2sql.main -d database_store/hotel.sql -l lang_store/english.csv -t thesaurus_store\th_english.dat -j output.json -i "What are the azertyuiop with nbLit greater than 3?"

The result is: (it's correct)

SELECT *
FROM chambre
WHERE chambre.nbLit > '3';

I noticed with the following lines in the thesaurus dictionary doesn't work. You need to add another value as above.

chambre|1
(noun)|azertyuiop

I need to figure out the way they retrieve values. Why does it return NoneType? Why doesn't single synonym work?

Change the first few lines in load method in thesaurus.py file to below:

    def load(self, path):
        with open(self._generate_path(path)) as f:
            # content = f.readlines()
            content = f.read().splitlines()

Now its working even id we dont add an extra pipe at the end ref: https://stackoverflow.com/questions/12330522/how-to-read-a-file-without-newlines

rakesh160 avatar Apr 09 '20 14:04 rakesh160