package org.lexvo.uwn.examples; import java.io.File; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; import java.util.Iterator; import org.lexvo.uwn.Entity; import org.lexvo.uwn.Statement; import org.lexvo.uwn.UWN; /** * Simple Example of how to use the UWN API * * @author Gerard de Melo */ public class SimpleExample { /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { // Instantiate UWN, providing a pointer to the plugins directory. UWN uwn = new UWN(new File("plugins/")); // Look up all meaning entity IDs for the French word "souris". // The ISO 639-3 code for French is "fra". For English use "eng". Please refer to // http://www.sil.org/iso639-3/codes.asp // for other language codes. System.out.println("Identifiers for Meanings of the French word 'souris'"); Iterator it = uwn.getMeanings(Entity.createTerm("souris", "fra")); while (it.hasNext()) { Statement meaningStatement = it.next(); Entity meaning = meaningStatement.getObject(); System.out.println(meaning + " with weight " + meaningStatement.getWeight()); } System.out.println(); // Once you have a meaning entity (or any other entity), use UWN.get() to look up more // information about them. System.out.println("All knowledge available for one of those meanings, e.g. descriptions, superclasses, etc."); System.out.println("(subject, predicate, object, weight)"); Entity meaning = new Entity("s/n2332156"); // this is one of the entities you get from the first iterator Iterator it2 = uwn.get(meaning); while (it2.hasNext()) System.out.println(it2.next()); } }