How to check if wordnet is already installed? - nltk

I know that we can check for resources like this:
try:
nltk.data.find('tokenizers/punkt')
except LookupError:
nltk.download('punkt')
But I can't find the way to do this for wordnet:
try:
nltk.data.find('wordnet') # ????/wordnet
except LookupError:
nltk.download('wordnet')
How can I make this check?

You can do:
nltk.find('corpora/wordnet')

Related

Not listing the file specified in regex with fnmatch

I am trying to list only specified files in my directory but getting only empty results. When I checked the expected results with regex tester (https://regex101.com/), I've got the expected results.
But in the python code, I can see nothing.
I tried some other combinations in regex string but nothing helped. I can list the whole directory though.
Am I doing something wrong ? It looks like quite simple solution so what am I missing ?
Code here:
import os
import fnmatch
directory = 'output/'
for filename in os.listdir(directory):
if fnmatch.fnmatch(filename, '^[20]+[0-9]+\.xlsx$'):
print(filename)
Can you please have a look and give me some hint ?
Many thanks
OK guys, thanks Wiktor for your reply. After that I look for a workaround and I came with this.
x = re.search("^[20]+[0-9]+\.xlsx$", filename)
if x is not None:
print(filename)
I am getting satisfying result so I think, I can close this one.
Many thaanks.

Cannot connect to MySQL with Weka

I am trying to connect a database to Weka 3.6.13 in Linux Elementary OS.
First, I had a problem with JDBC connection, solved by this answer changing the /usr/bin/weka file.
Now, when I load the database, this error comes:
Unknown data type: INT. Add entry in weka/experiment/DatabaseUtils.props.
However, I am trying to use explorer only, this file doesn't even exists in my installation.
I installed via sudo apt install weka.
What should I do?
Look inside the directory where your weka.jar file resides, and check if there exists a file called DatabaseUtils.props.
The Weka wiki says:
Weka only looks for the DatabaseUtils.props file. If you take one of
the example files listed above, you need to rename it first.
My file is different I think the actual name does not really matter, it's the filename extension that matters.
In my version of this file there is a section that looks like this:
... (snip...
# mysql-conversion / type-mappings
CHAR=0
TEXT=0
VARCHAR=0
STRING=0
LONGVARCHAR=9
BINARY=0
VARBINARY=0
LONGVARBINARY=9
BIT=1
BOOL=1
NUMERIC=2
DECIMAL=2
FLOAT=2
DOUBLE=2
TINYINT=3
SMALLINT=4
#SHORT=4
SHORT=5
INTEGER=5
INT=5
BIGINT=6
LONG=6
REAL=7
DATE=8
TIME=10
TIMESTAMP=11
#mappings for table creation
CREATE_STRING=TEXT
CREATE_INT=INT
CREATE_DOUBLE=DOUBLE
CREATE_DATE=DATETIME
DateFormat=yyyy-MM-dd HH:mm:ss
#database flags
checkUpperCaseNames=false
checkLowerCaseNames=false
checkForTable=true
setAutoCommit=true
createIndex=false
# All the reserved keywords for this database
Keywords=\
AND,\
ASC,\
BY,\
DESC,\
FROM,\
GROUP,\
INSERT,\
ORDER,\
SELECT,\
UPDATE,\
WHERE
# The character to append to attribute names to avoid exceptions due to
# clashes between keywords and attribute names
KeywordsMaskChar=_
#flags for loading and saving instances using DatabaseLoader/Saver
nominalToStringLimit=50
idColumn=auto_generated_id
If you do a google search for this file, another guy has posted his on github. The weka Wiki or SVN/Git-Repo might also list an offfical version somewhere (cannot find it right now), or you can open your weka.jar file as a zip file and extract the .props file (/src/main/java/weka/experiment/DatabaseUtils.props.mysql).
In any case, Mysql exists in many different versions, and I think you can even switch the query engine inside mysql. So I cannot express any guarantees that any of these 2 .props files shown here really work for you. You should experiment a bit.

Sphinx indexer «No error» error

I have 25GB TSV file and trying to import it with command:
D:\sphinx\bin>indexer.exe -c D:\sphinx\sphinx.conf products --rotate
It works some time, but then shows error
ERROR: index 'products': source 'products_tsv': read error 'No error' (line=4595827, pos=908, docid=4595827).
But record at line 4595827 have no problems.
I have two questions:
What's usually causes this problem?
Does indexer have any flags for ignoring errors?
Lost a lot of time on checking datafile and found a lot of hidden symbols such as SYM (\U001A), NULL (\0000) and a more of them, which turns Sphinx crazy.
Simply(if «simply» can be said about 25GB file) replaced all SYM to ' and removed others.
We moved forward and faced another issue, but this is another question.
Try to add extra line break after the last line in your .tsv data source, so the last line is empty. In my case it helped. Thanks to #stefobark and his repository stefobark/index_tsv

dpkg-shlibdeps: error: no dependency information found for

I'm compiling a deb package and when I run dpkg-buildpackage I get:
dpkg-shlibdeps: error: no dependency information found for /usr/local/lib/libopencv_highgui.so.2.3
...
make: *** [binary-arch] Error 2
This happens because I installed the dependency manually. I know that the problem will be fixed if I install the dependency (or use checkinstall), and I want to generate the package anyway because I'm not interested on dependency checking. I know that I can give to dpkg-shlibdeps the option --ignore-missing-info which prevents a fail if dependency information can't be found. But I don't know how to pass this option to dpkg-shlibdeps since I'm using dpkg-buildpackage and dpkg-buildpackage calls dpkg-shlibdeps...
I have already tried:
sudo dpkg-buildpackage -rfakeroot -d -B
And with:
export DEB_DH_MAKESHLIBS_ARG=--ignore-missing-info
as root.
Any ideas?
use:
override_dh_shlibdeps:
dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info
if your rule file hasn't the dh_shlibdeps call in it. That's usually the case if you've
%:
dh $#
as only rule in it ... in above you must use a tab and not spaces in front of the dh_shlibdeps
If you want it to just ignore that flag, change the debian/rules line from:
dh_shlibdeps
to:
dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info
Yet another way, without modifying build scripts, just creating one file.
You can specify local shlib overrides by creating debian/shlibs.local with the following format: library-name soname-version dependencies
For example, given the following (trimmed) ldd /path/to/binary output
libevent-2.0.so.5 => /usr/lib/libevent-2.0.so.5 (0x00007fc9e47aa000)
libgcrypt.so.20 => /usr/lib/libgcrypt.so.20 (0x00007fc9e4161000)
libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007fc9e3b1a000)
The contents of debian/shlibs.local would be:
libevent-2.0 5 libevent-2.0
libgcrypt 20 libgcrypt
libpthread 0 libpthread
The "dependencies" list (third column) doesn't need to be 100% accurate - I just use the library name itself again.
Of course this isn't needed in a sane debian system which has this stuff defined in /var/lib/dpkg/info (which can be used as inspiration for these overrides). Mine isn't a sane debian system.
Instead of merely ignoring the error, you might also want to fix the source of the error, which is usually either a missing or an incorrect package.shlibs or package.symbols file in package which contains the shared library triggering the error.
[1] documents how dpkg-shlibdeps uses the package.shlibs resp. package.symbols, files, [2] documents the format of the package.shlibs and package.symbols files.
[1] https://manpages.debian.org/jessie/dpkg-dev/dpkg-shlibdeps.1.en.html
[2] https://www.debian.org/doc/debian-policy/ch-sharedlibs.html
You've just misspelled your export. It should be like this:
export DEB_DH_SHLIBDEPS_ARGS_ALL=--dpkg-shlibdeps-params=--ignore-missing-info
dpkg-buildpackage uses make to process debian/rules. in this process, dpkg-buildpackage it might call dpkg-shlibdeps.
thus, the proper way to pass modify a part of the package building process is to edit debian/rules.
it's hard to give you any more hints, without seeing the actual debian/rules.
Finally I did it in the brute way:
I edited the script /usr/bin/dpkg-shlibdeps, changing this :
my $ignore_missing_info = 0;
to
my $ignore_missing_info = 1;
You can use this:
dh_makeshlibs -a -n
exactly after dh_install

Vanilla MySQL access from Ruby 1.9 on Snow Leopard

I am running Ruby 1.9 (ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-darwin10]) on Slow Leopard (installed via MacPorts).
I then installed the Ruby MySQL client library via MacPorts:
install rb19-mysql
Trying to use it I get the following error:
db.rb:4:in `initialize': wrong number of arguments(4 for 0) (ArgumentError)
from db.rb:4:in `new'
from db.rb:4:in `'
My code:
require 'mysql'
require 'pp'
dbh = Mysql.new("localhost", "testuser", "testpass", "test")
puts "Server version: " + dbh.get_server_info
It seems like I am missing something very basic here.
Did I install the right client library?
I am using it correctly?
Am I missing some other dependencies?
Would appreciate if someone could point me in the right direction.
Thanks!
What you're looking for is:
dbh = Mysql.real_connect("localhost", "testuser", "testpass", "test")
I have never written a line of Ruby in my life so maybe I'm going to embarrass myself, but don't you have to initialize Mysql first? I'm quite sure the fact that the function expects 0 parameters means it doesn't exist yet.
In the test file of the package you mention (you got me curious), I see the following line:
assert_nothing_raised{#m = Mysql.init}
your syntax seems to be correct, however. From the same test file
assert_nothing_raised{#m = Mysql.new(#host, #user, #pass, #db, #port, #sock, #flag)}
I would assume you need to do a Mysql.init() first.
If I'm wrong, let me know and I'll remove the answer.
Your code looks solid to me; it matches the examples given on the rb19-mysql homepage very well.
my = Mysql.new(hostname, username, password, databasename)
st = my.prepare("insert into tblname (col1,col2,col3) values (?,?,?)")
st.execute("abc",123,Time.now)
st.prepare("select col1,col2,col3 from tblname")
st.execute
st.fetch # => ["abc", 123, #<Mysql::Time:2005-07-24 23:52:55>]
st.close
Which would seem to indicate that there's probably something not quite right with the port install. There were all kinds of issues with MacPorts not working properly after snow leopard upgrades - are you falling victim to this? I had to rebuild all my ports before they worked properly.
Also (and I know this is like religion to some people), you might want to consider ditching the MacPort version and just grab the MySql gem. For whatever reason, using the gems has been a far more pleasurable experience for me.
Hope that helps - good luck!