Re: Issues accessing class attributes of external package distance function
Peter Reutemann <[email protected]> Wed, 20 Jul 2022 14:57:51 +1200
| Newsgroups | gmane.comp.ai.weka |
|---|---|
| Message-ID | <CAHoQ12+b6vK7jo9m8f_DyZQYfdwNmpduzRReFRSNfGxd6yGvsQ@mail.gmail.com> |
> > I just committed some changes to pww3 that allow you to access or call > > non-public Java fields/methods > > Setting accessible would allow this I think. A simple subclass changing the protected access still seems easier to me in this case. It’s also a legitimate java way to do this without bypassing or modifying the access of the class. I didn't want to bog this thread down with specifics... pww3 communicates with a JVM in the background that holds the Weka classes/processes. It uses the python-javabridge library under the hood and a lot of ugly-looking calls via method signatures behind the scenes to make it look nice/pythonic (signatures are obtained via "javap -public -s ..."). Some additional helper methods (on the Java side of pww3 and with Python wrappers again) set the accessible flag, to make these non-public fields/methods available. [...] > Possibly this makes it easier from Python if the intention is really to have little or nothing to do with the java. That's the point. The idea is not to have to add additional Java classes to get around these access issues. Especially, when people are not familiar with Java and how to create Weka packages. > If the intention isn’t to include this in a Weka java based package I’m still unclear on how it is meant to be provided. Again possibly I don’t understand well enough how the Python works. Not quite sure what you mean. The DilcaDistance class (which is already available as a Weka package) has a protected field. OP wants to access this field directly and turn the stored matrices into numpy arrays with no precision loss which currently happens when parsing the toString() output of said class. Accessing non-public members/methods is not a very common use-case, but sometimes required when you need internally computed/held data structures for further processing. Over the years, I've had to sub-class plenty of classes to get access to such data structures. Annoying, but not really a biggie when you're already programming in Java. Cheers, Peter -- Peter Reutemann Dept. of Computer Science University of Waikato, NZ +64 (7) 858-5174 (office) +64 (7) 577-5304 (home office) https://www.cs.waikato.ac.nz/~fracpete/ http://www.data-mining.co.nz/ _______________________________________________ Wekalist mailing list -- [email protected] Send posts to [email protected] To unsubscribe send an email to [email protected] To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html