kmadathil / sanskrit_parser

Parsers for Sanskrit / संस्कृतम्
MIT License
69 stars 21 forks source link

A readme is now in order #8

Closed drdhaval2785 closed 7 years ago

drdhaval2785 commented 7 years ago

I saw your impressive speed up. So just wanted to run SanskritLexicalAnalyzer.py as shown in the comment. But it gave me error No module named base.SanskritBase

Maybe a line or two of setup would be in order.

Maybe I am not able to setup the directory structure as it should have been.

kmadathil commented 7 years ago

run source sourceme from the sanskrit_parser root directory. That'll setup your PYTHONPATH so all subdirectories are visible.

This will probably not be the final directory structure - as Vishvas requested, we'll probably break this up and so that it'll be easier to reuse parts. For now, since this changes by the minute, let the current structure be.

drdhaval2785 commented 7 years ago

I did source sourceme, but the problem still lingers

 python SanskritLexicalAnalyzer.py astyuttarasyAMdishi --split
Traceback (most recent call last):
  File "SanskritLexicalAnalyzer.py", line 12, in <module>
    import base.SanskritBase as SanskritBase
ImportError: No module named base.SanskritBase

Anything to do with windows machine ? I run it in git bash terminal.

kmadathil commented 7 years ago

@drdhaval2785

Updated README.md Can you run echo $PYTHONPATH and cut-paste your output here?

Also cd sanskrit_parser, and see if you can do the following

sanskrit_parser (master)*$ python -i 
Python 2.7.13 |Anaconda custom (64-bit)| (default, Dec 20 2016, 23:09:15) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import base
>>> import base.SanskritBase
drdhaval2785 commented 7 years ago
$ echo $PYTHONPATH
:/e/c_drive/xampp/htdocs/sanskrit_parser:/e/c_drive/xampp/htdocs/sanskrit_parser/../inriaxmlwrapper:/e/c_drive/xampp/htdocs/sanskrit_parser:/e/c_drive/xampp/htdocs/sanskrit_parser/../inriaxmlwrapper:/e/c_drive/xampp/htdocs/sanskrit_parser:/e/c_drive/xampp/htdocs/sanskrit_parser/../inriaxmlwrapper
$ python -i
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import base
>>> import base.SanskritBase
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "base\SanskritBase.py", line 2, in <module>
    from indic_transliteration import sanscript
ImportError: No module named indic_transliteration
>>> exit()
drdhaval2785 commented 7 years ago

installed indic_transliteration via pip. That error is now gone.

kmadathil commented 7 years ago

Great! Let me know what you think. I'm closing this issue, please reopen if you face more trouble.

drdhaval2785 commented 7 years ago

importing base via python -i works. But the error in terminal still remains the same.

dell user@dell MINGW64 /e/c_drive/xampp/htdocs/sanskrit_parser/lexical_analyzer (master)
$ python SanskritLexicalAnalyzer.py astyuttarasyAMdiSi --split
Traceback (most recent call last):
  File "SanskritLexicalAnalyzer.py", line 12, in <module>
    import base.SanskritBase as SanskritBase
ImportError: No module named base.SanskritBase
kmadathil commented 7 years ago

How did you install indic_transliteration? Did you use pip?

drdhaval2785 commented 7 years ago

Yes. pip install indic_transliteration

kmadathil commented 7 years ago

Try importing base using python -i but from the lexical_analyzer directory. If that works, please try import SanskritLexicalAnalyzer and dump the output here.

drdhaval2785 commented 7 years ago

Not possible to import base from lexical_analyzer directory

dell user@dell MINGW64 /e/c_drive/xampp/htdocs/sanskrit_parser/lexical_analyzer (master)
$ python -i
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import base
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named base
kmadathil commented 7 years ago

This indicates a PYTHONPATH problem. If you have the same PYTHONPATH as mentioned in an earlier comment, this should not happen. Possibly a Windows issue.

This is what should happen - the sanskrit_parser directory should be on PYTHONPATH, so import base will work (the base subdirectory will be visible to python, and it can see a __init__.py there). Somehow that's not happening for you. Please see if you can think of something based on this.

I will look into this further once I have access to a Windows machine later in the day.

drdhaval2785 commented 7 years ago

It indeed seems to be an windows+bash issue. Works as described in my ubuntu machine.

avinashvarna commented 7 years ago

Works for me on windows + git bash. I did essentially what dhaval did: cd to sanskrit_parser export PYTHONPATH=$PWD cd to inriaxmlwrapper export PYTHONPATH=$PYTHONPATH:$PWD $ echo $PYTHONPATH /c/Users/ALVARNA/Documents/personal/samskritam/research/sanskrit_parser:/c/Users/ALVARNA/Documents/personal/samskritam/research/inriaxmlwrapper $ python lexical_analyzer/SanskritLexicalAnalyzer.py astyuttarasyAMdishi --split Parsing of XMLs started at 2017-07-05 14:47:18.853000 666994 forms cached for quick search Parsing of XMLs completed at 2017-07-05 14:47:24.909000 Input String: astyuttarasyAMdishi Input String in SLP1: astyuttarasyAMdiSi Start split: 2017-07-05 14:47:27.659000 End split: 2017-07-05 14:47:27.659000 [[u'asti', u'ut', u'tara', u'syAm', u'diSi'], [u'asti', u'ut', u'taras', u'yAm', u'diSi'], [u'asti', u'uttas', u'asyAm', u'diSi'], [u'asti', u'uttara', u'syAm', u'diSi'], [u'asti', u'uttaras', u'yAm', u'diSi'], [u'asti', u'uttarasyAm', u'diSi']]

kmadathil commented 7 years ago

@avinashvarna Can you try running in the lexical_analyzer directory? That's when @drdhaval2785 saw the error.

drdhaval2785 commented 7 years ago

By following the steps delineated by @avinashvarna above, I am now able to run both in sanskrit_parser and lexical_analyzer directories. It seems that the generic sourceme method does not apply in windows machine.

drdhaval2785 commented 7 years ago

And it seems that the method shown above is stored in only session. Whenever I reopen git bash, it is forgotten. I need to rerun the above code over again whenever I close and open git bash.

avinashvarna commented 7 years ago

@drdhaval2785 Once you follow the above steps and get it set up correctly, run this command to add the environment variable setup into your bashrc echo "export PYTHONPATH=\${PYTHONPATH}\${PYTHONPATH:+:}$PYTHONPATH" >> ~/.bashrc

Next time you start git bash, the environment variable should be setup correctly to run the scripts.

drdhaval2785 commented 7 years ago

I already have a .bashrc working for some SSH key. Tried adding this to that .bashrc file, but to no avail. But at least now I am able to run the code on windows laptop. So not have to stick myself on my ubuntu desktop at fixed place. @kmadathil may like to create something for windows which is a bit easier.

avinashvarna commented 7 years ago

The command that I posted "appends (>>)" that export line to your .bashrc, so it should not impact your existing setup. If you are manually modifying your .bashrc, did you add export PYTHONPATH=${PYTHONPATH}${PYTHONPATH:+:}$PYTHONPATH to it? Strange that it doesn't work.