Configure New NLTK Path - python

I am working with nltk in python. I imported the package and downloaded the additional data just fine, but I want to be able to append a new directory to store nltk_data.
When I tried this fix found at this link (How to config nltk data directory from code?)
nltk.data.path.append("path")
I received this error:
AttributeError: 'str' object has no attribute 'append'
What am I doing wrong?

you can try checking what nltk.data.path stores.
most probably you assigned the path as string (may be in a notebook session)
nltk.data.path.append = "folder path" (this is incorrect way)
you should first clear your session or restart your session if you made above change.

Related

str object is not callable while importing the dataset on jupyter notebook. what to do?

I tried to import the dataset on jupyter notebook. But it indicates error as str object is not callable,even the pathway of the file are obsolutely okay.
or Are there any problems with anaconda? help me out!!
here is my code after importing the libraries:
df=pd.read_csv('Nutrients.csv')
Even everything is okay it still shows str object is not callable
Now i need to load the dataset.
In pandas.read_csv, the string which is passed inside as a parameter is the name of the file. If the file does not exist, then python just considers the value as a string which in your case is the same.
Try checking out the location of the jupyter notebook that you are running the code in and the file you want to access. According to your code, they should be in the same location.

Getting the file name of an ipython notebook

For python files I can get the file name and use to as a prefix for the generated results using:
prefix = os.path.splitext(os.path.basename(main.__file__))[0]
But this fails for ipython notebooks with the following error:
---> 23 return os.path.splitext(os.path.basename(main.__file__))[0]
AttributeError: module '__main__' has no attribute '__file__'
Is there a reasonable way to get the current notebook's name?
Previously suggested solutions, like ipyparams and ipynbname don't seem to work for me.
Someone already posted a workaround using JavaScript.
You can find the original question here: https://stackoverflow.com/a/44589075

Anylogic, parameter variation experiment pipeline source error

I am trying to create a parameter variation based on a single python script run using the pipeline jar. I manually added a variable called 'pyCommunicator ' of the type other 'PyCommunicator' with initial value new 'PyCommunicator()'.
In the 'initial experiment set' block of the properties section, I import the python file via 'pyCommunicator.run("import GA");'
However, when I try to run the parameter variation I get the error code "PyCommunicator.java:669' indicating that the source code is not present. It also states '669 is not a valid line number in com.anylogic.libraries.pypeline.PyCommunicator'
When I add the jar file at the 'Change Attached Source' option the error does not change. The jar file is in the same folder as the anylogic and python files. I am not sure why the error occurs now. Has anybody experienced this issue before?
This is what it shows if you click on the error:

gstreamer plugin error - No such element or plugin 'pocketsphinx' (Mac)

I tried to follow this tutorial but failed.
I am confused about which string to assign to GST_PLUGIN_PATH.
In other words, this is my current GST_PLUGIN_PATH( according to some searching on forums)
usr/local/Cellar/gstreamer/1.14.4/
But I also have tried this string because the mentioned tutorial made me do so:
/usr/local/Cellar/cmu-pocketsphinx/0.8/lib/python2.7/site-packages/
the "pocketsphinx.so" file is inside the latter one while it is not inside the former one.
Neither of the above strings works;
gst-inspect-1.0 pocketsphinx
gave me this message no matter which value I assigned to GST_PLUGIN_PATH:
No such element or plugin 'pocketsphinx'
Previously, I also copy the .pc files.
$cd /usr/local/lib/pkgconfig
$cp gstreamer-1.0.pc
/usr/local/Cellar/cmu-pocketsphinx/0.8/lib/python2.7/site-packages/
$cp gstreamer-base-1.0.pc /usr/local/Cellar/cmu-pocketsphinx/0.8/lib/python2.7/site-packages/
$cp gstreamer-plugins-base-1.0.pc
/usr/local/Cellar/cmu-pocketsphinx/0.8/lib/python2.7/site-packages/
Please help, thank you.

create a new odt-file with python

I have a folder "myfolder" which was created when I had unzipt an odt-file. I had delete the content.xml in the folder. Now I want to add a file called "content.xml" with data in it (here in the variable "content" is the xml-styled text). I tried this:
with zipfile.ZipFile('myfolder', mode='a', compression=zipfile.ZIP_DEFLATED) as zf:
zf.writestr('content.xml', content)
I get an odt-file but it is damaged. when I unzip it there is only the content.xml in it. the mode parameter is 'a' so I thougt it will append the content.xml to the other files.
Can anybody help?
You can try to use the package odfpy.
you can see some info here and here
Odfpy is a library to read and write OpenDocument v. 1.2 files. The
main focus has been to prevent the programmer from creating invalid
documents. It has checks that raise an exception if the programmer
adds an invalid element, adds an attribute unknown to the grammar,
forgets to add a required attribute or adds text to an element that
doesn’t allow it. It's on pipy, so you can install it with
you can install it with pip:
pip install odfpy

Categories