ani-hovhannisyan / kanji-visualization

Kanji words visualization graph draws relational graph for kanjis of particular words in Japanese. Aim is to understand the relational graph of one kanji within different words and it's relations to all possible words.
MIT License
5 stars 1 forks source link

[backend]Create Info controller #48

Closed teruto725 closed 2 years ago

teruto725 commented 2 years ago

Create Info controller

Class Info controller
offer only get_kanji_info function
- Input: kanji (ex 山)
- Output: dictionary (ex { “onyomi”: san, “kunyomi”: yama})
- Additional you can: return english meaning also
- 
TakumiHiraide commented 2 years ago

I report about the error. I installed requirements.txt that includes jamdict by "pip install -r ./backend/requirements.txt". However, backend/Infocontroller.py doesn't work. The error is below. File "/Users/takumi-hi/kanji-visualization/kanji-visualization/backend/InfoController.py", line 3, in from jamdict import Jamdict ModuleNotFoundError: No module named 'jamdict'

TakumiHiraide commented 2 years ago

The code InfoController.py is below.

pip install jamdict jamdict-data

from jamdict import Jamdict class InfoController:

from jamdict import Jamdict

def get_jamdict_data():
    jam = Jamdict()
    print("query: ", end="")
    query = input()
    result = jam.lookup(query)
    index = -1
    print(result)

get_jamdict_data()

wowry commented 2 years ago

@TakumiHiraide Sorry, the current ./backend/requirements.txt contains only the libraries that were needed to build the development environment, so please add more libraries as needed. In this case, please run pip install jamdict jamdict-data on your terminal, and edit ./backend/requirements.txt as follows:

flake8
black
mypy
pytest
pre-commit
fastapi
uvicorn
jamdict
jamdict-data

This will ensure that the latest dependent libraries are installed when others run pip install -r ./backend/requirements.txt.

TakumiHiraide commented 2 years ago

Sorry, I did what you said, but it still doesn't work. Maybe I have another problem.

TakumiHiraide commented 2 years ago

The error is same from jamdict import Jamdict ModuleNotFoundError: No module named 'jamdict'

wowry commented 2 years ago

@TakumiHiraide By the way, can you run this file without errors? https://gist.github.com/wowry/840715df27d75171c5a8456e76275862

TakumiHiraide commented 2 years ago

No, not yet because the first "from jamdict import Jamdict" throws an error "ModuleNotFoundError: No module named 'jamdict' ".

wowry commented 2 years ago

@TakumiHiraide OK, then please run pip list and check the list contains the libraries you expected.

image

TakumiHiraide commented 2 years ago

I made sure that list contained "jamdict and jamdict-data" スクリーンショット 2022-02-04 20 10 52

TakumiHiraide commented 2 years ago

Does it work for you?

TakumiHiraide commented 2 years ago

My folder structure is here. I want to run "InfoController.py" which is same to "sample_jamdict.py"

スクリーンショット 2022-02-04 20 49 41

wowry commented 2 years ago

Hmm... It looks strange (because kanji-visualization in kanji-visualization), but there seems to be no problem. Yes, it works in my local environment. Could you send me the screenshot of your InfoController.py?

TakumiHiraide commented 2 years ago

InfoController2 is completely the same "sample_jamdict.py" you prepare. Both programs throw the same error "ModuleNotFoundError: No module named 'jamdict' ". スクリーンショット 2022-02-04 22 20 48 スクリーンショット 2022-02-04 22 23 33

ani-hovhannisyan commented 2 years ago

Ok so may I summarize? As far as I understood, we still didn't understand where isn't visible the jamdict module, in your local machine? or in VisualStudio terminal environment? I just tried same and it worked on my machine so from my understanding to have nested directories isn't good, because you have now 2 git repositories nested each other, as said @wowry the kanji-visualization directory is nested in KANJI-VISUALIZATION directory. TEST ENVIRONMENT Can you do this to check if jamdict is working in whole computer? Step 1. Open new terminal without visual studio code and type: $ python3 Step 2. Now type: from jamdict import Jamdict Step 3. if you see nothing is printed after 2nd step then jamdict worked! That means the problem is that you have nested directories, MAYBE! Please try to make one directory with one .github directory inside (not nested). But if it 2nd step says can't find .... then jamdict isn't installed in your local machine.

To fix that at this point and to continue coding, you can open again new terminal and type same as @wowry said before : $ pip install jamdict jamdict-data (I guess as you see the pip list this won't be the case now)

TEST CODE But if you want to make sure if simple jamdict code will work try this testing steps:

  1. Open new terminal and type: $ cd ~/; mkdir test-jamdict; cd test-jamdict; touch jd.py
  2. Now just open the jd.py file from test-jamdict folder and paste this code:
    
    from jamdict import Jamdict
    jam = Jamdict()
    result = jam.lookup('食べ%る')
    for entry in result.entries:
    print(entry)
    for c in result.chars:
    print(repr(c))
    print("If you see this message them JAMDICT WORKED in your computer !!!")

3. Now go back to the same terminal and type
 $ `python3 jd.py`
4. Now you should see the printed last message
5. OPTIONAL. Now go to your project directory then open terminal and do the same as from TEST CODE ?
wowry commented 2 years ago

That's exactly what I want to say!

ani-hovhannisyan commented 2 years ago

That's exactly what I want to say!

Sorry for stoling your thoughts ))) I saw many emails coming from this issue and checked in my side then typed same steps as I did in my machine ^^

wowry commented 2 years ago

Nice, thank you very much for your support!

TakumiHiraide commented 2 years ago

Everyone, thank you so much. I fixed nested directories, but it doesn't work. So, I use terminal application, then I don't know why, but it worked. スクリーンショット 2022-02-05 0 08 52 .

ani-hovhannisyan commented 2 years ago

Great, then you can move on to coding. It "worked" because jamdict is really installed in your machine. About "didn't work" we'll think of that later, as we don't have much time on development environment (VisualStudio specific) fixes this week.

wowry commented 2 years ago

Maybe following the steps in the link below will be solve this error, but yes, we don't have much time this week as ani san said, so don't think too much! :)

https://qiita.com/Toyoizumi-Hiroyuki/items/db8709e3dd821750d570#python%E5%AE%9F%E8%A1%8C%E7%92%B0%E5%A2%83%E3%81%AE%E8%A8%AD%E5%AE%9A

TakumiHiraide commented 2 years ago

I made InfoController, but "kanji_info" and "error_info" are list type. Is it OK? I'm not sure if this will be reflected in the frontend.

スクリーンショット 2022-02-09 10 15 49

スクリーンショット 2022-02-09 10 14 24

teruto725 commented 2 years ago

Sorry. It's not good. You should use dictionary instead of list. you chan just fix likes below.

kanji_info = {"onyomi":yomi, "meaning", meaning} 

and kanji info is also needed kunyomi right?

TakumiHiraide commented 2 years ago

Thank you for your advice. Now the code can output the kun-yomi, on-yomi, and meaning using the dict type as shown below. But I'm not confident about my code, because I assume the first part of [Entries] to be kun-yomi and the second part to be on-yomi. I'm really sorry スクリーンショット 2022-02-09 16 31 13 .

TakumiHiraide commented 2 years ago

スクリーンショット 2022-02-09 16 30 42

スクリーンショット 2022-02-09 16 30 08

スクリーンショット 2022-02-09 16 29 33

スクリーンショット 2022-02-09 16 29 11

TakumiHiraide commented 2 years ago

スクリーンショット 2022-02-09 16 28 06

スクリーンショット 2022-02-09 16 28 49

ani-hovhannisyan commented 2 years ago

Commit 3368901c

ani-hovhannisyan commented 2 years ago

We've doen pair programmign with Hiraide san and Ihara san. And fixed local environment issues, not all works fine.