Signbank / Global-signbank

An online sign dictionary and sign database management system for research purposes. Developed originally by Steve Cassidy/ This repo is a fork for the Dutch version, previously called 'NGT-Signbank'.
http://signbank.cls.ru.nl
BSD 3-Clause "New" or "Revised" License
19 stars 12 forks source link

AnnotatedGloss model field gloss [CODE] #1309

Closed susanodd closed 2 months ago

susanodd commented 3 months ago

[THIS ISSUE IS ABOUT CODE]

It seems the data stored in the model AnnotatedGloss, the field stored in "gloss" is actually an ID, not a foreign key. So an additional lookup is needed to retrieve the Gloss object using this ID. (Normally, if you retrieve the value in a foreign key field it should be an object.)

This method doesn't work:

https://github.com/Signbank/Global-signbank/blob/afaa5ce1006d80e60aee8580606469ee8edd8f50/signbank/dictionary/models.py#L3956-L3957

Inside my loop, I have both the annotated gloss (variable this) and the gloss object (this_gloss), and the following:

    this = AnnotatedGloss.objects.get(id=annotatedgloss_id)
    this_gloss = Gloss.objects.get(id=this.gloss_id)

......

    print(this.annotatedsentence)
    print(this.show_annotationidglosstranslation())
    print(this_gloss.annotationidglosstranslation_set.all())

where "this" is an annotated gloss and "this_gloss" is the gloss. The second print does not output anything, but the first and third do.

Originally posted by @susanodd in https://github.com/Signbank/Global-signbank/issues/1305#issuecomment-2277504193

susanodd commented 3 months ago

There might need to be a migration to make the ForeignKey be an object and not just an ID ?

(We had this problem with handshapes at the start because they started out as a machine value and needed to become an object. @vanlummelhuizen is an expert in this. Maybe he can take a look.)

Jetske commented 3 months ago

I'm not sure that is the problem because the function does work in other places, and gloss is linked to as ForeignKey See in AnnotatedGloss model: gloss = models.ForeignKey("Gloss", on_delete=models.CASCADE)

What do you want to retrieve?

Maybe try print(this.gloss.annotationidglosstranslation_set.all()) to check what that does. Maybe the filter in show_annotationidglosstranslation is too strict.

susanodd commented 3 months ago

I'm not sure that is the problem because the function does work in other places, and gloss is linked to as ForeignKey See in AnnotatedGloss model: gloss = models.ForeignKey("Gloss", on_delete=models.CASCADE)

What do you want to retrieve?

Maybe try print(this.gloss.annotationidglosstranslation_set.all()) to check what that does. Maybe the filter in show_annotationidglosstranslation is too strict.

No, I'm not trying to retrieve the things I printed. I was trying to debug the code. I only wanted to get the Gloss out of the AnnotatedGloss.

    this = AnnotatedGloss.objects.get(id=annotatedgloss_id)
    this_gloss = Gloss.objects.get(id=this.gloss_id)

It doesn't work to do this.gloss for example. It's not a Gloss object. I had to write the second line to retrieve an object.

I suspect it's to do with whether it's joining tables or trying to get an object. It can do fine if it's joining tables, but it can't get the object.

I added a pre_fetch but that didn't solve the above problem.

  1. for the "annotatedsentence" reference (also inside the AnnotatedGloss), can there be multiple for the same sentence with slight variations on the actual text? (See screenshot) If the user updates the sentence, is the code adding more annotated sentence objects and not deleting the previous?

Here is an example screenshot with the Sentence ID in the list view. To me it looks like variations on the same sentence, like the end of the sentence is cropped in some, so it looks like there are some objects that ere edited but the old ones not removed? (Sentence ID 21, 22.)

Here is the screenshot of AnnotatedGloss list, with the column containing the Annotated Sentence.

annotated-gloss-list-with-sentence-and-id

Btw, very cool! I had no idea there were so many sentences!

susanodd commented 3 months ago

Just a guess thinking about this, it may have something to do with how data is created. Whether the constructor is used, or whether the create_or_get is used. The constructor creates an object, the create_or_get inserts into the table. (Need to ask @vanlummelhuizen about this.)

susanodd commented 2 months ago

This has been programed away in various places.