0
votes

I've installed weka python wrapper on Windows 7. And I tried running the sample code:

import weka.core.jvm as jvm
jvm.start()

data_dir = "E:/Files/Fourth/"

from weka.core.converters import Loader
loader = Loader("weka.core.converters.TextDirectoryLoader")
datasets = [
    data_dir + "File 1",
    data_dir + "File 2",
    data_dir + "File 3",
    data_dir + "File 4",
    data_dir + "File 5"

    ]
data = loader.load_file(datasets)
data.delete_last_attribute()
print(data)

and I received the following error:

Traceback (most recent call last):
 File "C:/Python27/weekaa.py", line 16, in <module>
  data = loader.load_file(datasets)
 File "C:\Python27\lib\site-packages\weka\core\converters.py", line 67,  in load_file
  self.enforce_type(self.jobject, "weka.core.converters.FileSourcedConverter")
 File "C:\Python27\lib\site-packages\weka\core\classes.py", line 155, in  enforce_type
    raise TypeError("Object does not implement or subclass " + intf_or_class  + "!")
TypeError: Object does not implement or 
  subclass  weka.core.converters.FileSourcedConverter!

I tried solution in previous asked question (in stackoverflow) by adding class path to weka.jar or python-weka-wrapper but didn't work. The error doesn't appear when loading .arff file type.

Is there a solution to load text files?

Note: Each file in dataset has set of text document files(for later clustering)

1

1 Answers

0
votes

Weka's TextDirectoryLoader class cannot be used with python-weka-wrapper up to version 0.2.2. The upcoming release 0.2.3 (or the github repository) contain a new Python wrapper called TextDirectoryLoader available from the weka.core.converters module which allows you to use this class now. This was also answered on the python-weka-wrapper mailing list.

from weka.core.converters import TextDirectoryLoader
text_dir = "/the/directory/you/want/to/load"
loader = TextDirectoryLoader(options=["-dir", text_dir, "-F", "-charset", "UTF-8"])
data = loader.load()
print(unicode(data))