I am trying to find synonyms of some words(String type) in java using Wordnet java api. I have difficulties though in figuring out how it works.
I found this link http://lyle.smu.edu/~tspell/jaws/doc/edu/smu/tspell/wordnet/impl/file/ReferenceSynset.html#getTagCount%28java.lang.String%29 which I though it is useful, but still I don't know how to start. Do I have to create a ReferenceSynset object and then find its synonyms, and how can this be done? Or is there another easier way? Please help!
Thanks in advance!
JAWS - "Java API for WordNet Searching" has been created exactly for this purpose. It is possible that you haven't installed it right. In the same domain that you mention (smu.edu) there are instructions for installing JAWS.
First, you will need to download the executable and Wordnet itself.
Get the *.jar file
Download the wordnet database files to the appropriate directory (instructions here)
Once you have done this you should next try the example program. First, make sure that it works unmodified. If you get that working, you should see a bunch of synsets when you type:
java TestJAWS <your word here>
If that works, you can start modifying the code to suit your purpose.
Hope that helps.
Related
I'm trying to read a .qm translation files with Java.
.qm files are binary files. I don't have access to the .ts files.
And I don't find much info on these .qm files.
How are they structured ?
Regards,
There's no documentation that I know of, but if you look at QTranslator::load you should be able to follow the format of the QM file.
You will probably need to reimplement QTranslator in Java, as you need not only the ability to load the files, but also to extract and apply translations in Qt fashion.
As per request of OP:
You could use those files by using the Qt libraries and JNI. By using the translator in a c++ dll you can translate strings easily. However, you cannot extract the files or list the contained translations. But if all you need is the actual translation, this solution should work.
I cannot give a real example, because I only now how it works in theory, I haven't tried it, because it's not trivial. But if you are eager to try it out, the general idea would be:
Create a C++ dll and build it against QtCore. The easiest way is to download Qt from their website qt.io. You can for example create a default library project with QtCreator. Note: Besides Qt5Core.dll, Qt requires other libraries to correctly run. They are all included in the installation, but once you deploy your application, those of course have to be includes as well.
Include JNI to the C++ project and link against it. if you're new to this, here is a nice tutorial: Java Programming Tutorial
Create your wrapper methods. Methods in cpp you can call from java that take java strings, convert them to QString, translate them with QTranslator and convert them back.
Load the library in Java and execute those methods
Important:
First, I don't know how java handles dll dependencies. If you encounter errors while loading the dll, it's probably because dependencies of your dll are not present. Second, Qt typically requires a QCoreApplication running in the main thread for most of it's operations. I tested the translator without such an app, and it worked. So apparently for translations only the app is not required. However, depending on what you do in your dll, I think this is important to know.
If you need more details, feel free to ask.
I've been having terrible luck trying to get this to work, so I'm hopeful someone can help here.
In Java, I need to be able to take an HTML page with JavaScript within it and detect any JavaScript errors without, preferably without executing the JavaScript code.
I found this article:
Javascript parser for Java
And I've attempted to figure out how I'm supposed to use Caja to do this, but I'm having a difficult time finding any documentation with working examples of anything close to what I'm doing.
As a result I took a look at Nashorn also referenced in that article. I found a few examples which show how to execute JavaScript code from Java, but this doesn't process the whole HTML page. Even then, the execution doesn't seem to include the ability to validate common JavaScript functions (e.g. It hadn't heard of "alert").
Can anyone recommend something that might be able to do what I want, and point me in the right direction for their documentation or give me an example?
jshint as a standalone product seems to be a good fit for this:
it can run in java inside rhino (see https://github.com/jshint/jshint/)
a nodejs package exists (see https://www.npmjs.com/package/jshint)
it works with nashorn but it's quite tricky
I will only cover the technical difficulties around 3rd solution as I finally managed to make it work too...
Spoiler alert: "alert()" is not detected yet... Solution nb 2 will help there...
You first need to grab this specific release of jshint: https://github.com/jshint/jshint/releases/tag/2.4.4
Anything later than v2.7.0 will fail for now and I personally gave up patching intensively prototypes and namespaces... Releases from v2.4.4 until v2.6.3 work without modification but are limited in functionalities.
In the release notes, it's specifically written that "support for the Nashorn JavaScript engine" is working on this release. I'm using JDK8 nashorn 1.8.0_45 for this test.
Next step is to extract from this release this single file jshint-2.4.4/dist/jshint-rhino.js
Now you need to run nashorn/jjs in scripting mode and you need to be specific about the single file you wish to verify. In solution 2 (nodejs based) you can do multiple files or a complete hierarchy below a folder...
Create a simple file file.js:
function(){}
Now run the following command (please note the presence of -- ):
jjs -scripting jshint-rhino.js -- file.js
This will give you the following output:
Missing name in function declaration. (file.js:1:9)
> function(){}
So this covers the how to run jshint in a simple manner with nashorn... With the 3rd solution, at least you can find missing semicolons and several typical errors. But it's not a silver bullet and to me it's not a real alternative.
My personal preference would be to stick to solution 2 only. If you've the possibility to install either nodejs or iojs on your dev platform, go and grab https://www.npmjs.com/package/jshint. Not only will you be able to do more than the 3rd solution, you'll also be able to configure a jshintrc file as described at http://jshint.com/docs/
I have to make lexical graph with words within a corpus. For that, I need to make a program with word2vec.
The thing is that I'm new at this. I've tried for 4 days now to find a way to use word2vec but I'm lost. My big problem is that I don't even know where to find the code in Java (I heard about deeplearning but I couldn't find the files on their website), how to integrate it in my project...
One of the easiest way to embody the Word2Vec representation in your java code is to use deeplearning4j, the one you have mentioned. I assume you have already seen the main pages of the project. For what concerns the code, check these links:
Github repository
Examples
I read on oracle that it is possible to create a custom FileSystem, but I can't really find much documentation on creating one. Could anyone link me to somewhere I can learn more about custom FileSystems?
Where I read about this:
http://docs.oracle.com/javase/7/docs/technotes/guides/io/fsp/filesystemprovider.html
A (Real) Simple Example
A very simple Java FileSystem to use as an example is nodet/githubfs. There are only a few classes and it will give you the flavor of how to implement a basic file system. The primary classes are:
GitHubFileSystem
GitHubFileSystemProvider
GitHubPath
Note that this file system does not implement all operations (which is part of the reason it is good as a high level example).
Experiment!
To experiment with using a custom FileSystem without any coding, a handy project is puniverse/javafs. It allows you to mount it as a FUSE and interact with it from a terminal. Setup is quite easy:
import co.paralleluniverse.javafs.JavaFS;
...
// Need to mkdir /tmp/mnt first
JavaFS.mount(fileSystem, Paths.get("/tmp/mnt"));
Thread.sleep(Long.MAX_VALUE);
Google opensourced a completely in-memory filesystem implementation called JimFS: https://github.com/google/jimfs
I know this is an old question but many people still want the actual answer, which is not here. The problem is that the documentation by Oracle (Sun), listed by the OP is missing critical information. What adds to the confusion is that the "demo" referenced by the doc is packaged in a confusing way. There is a Demo.java source file and src.zip and a zipfs.jar. The Demo.java is NOT a FileSystemProvider. Its a custom FileSystem. For it to work you have to add the zipfs.jar to the "extensions" folder of your JRE/JDK, so that when the Demo.getZipFSProvider() method is called, it will find the custom FileSystemProvider which returns the custom FileSystem. If you look in the src.zip you will find the code for the provider. If the Java documentation had been properly written this question would not have come up. Its confusing. Even the readme file in the demo makes no mention of the provider. Sad.
I want to find a library that I can use from my Java application that will allow me to access specific Javadoc in the scope of my project (I specify where Javadocs are located). Just like in Netbeans, I want to potentially access the Javadoc from html files locally and remotely, and from source.
I expect that I could use code from Netbeans to achieve this, but I don't know how, and I can't easily digest their documentation.
Today I started thinking about the same thing.
From CI point of view, I could use #author annotation to send e-mail to someone, who wrote a test that is failing with error, not with a failure.
Google didn't help me (or I didn't google deep enough), so I started wondering how to do it on my own.
First thing that came to my mind is writing a little tool that will check all *.java files specified in a directory, bound file name to annotations and allow user to perform some actions on them.
Is that reasonable?