/** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { System.out.println("Start \n*****************************\n"); String lLemma = "Italia"; PartOfSpeech pos2 = new BySimplerCanonicalPartOfSpeech(SimplerCanonicalPosTag.NOUN); String rLemma = "Venezia"; System.out.println("Looking for all rules from \"" + lLemma + "\" to \"" + rLemma + "\""); // test Wikipedia System.out.println("\nFrom the new WikiLexicalResource:"); Set<WikiExtractionType> extractionTypes = Utils.arrayToCollection( new WikiExtractionType[] { WikiExtractionType.REDIRECT, WikiExtractionType.CATEGORY, WikiExtractionType.LEX_ALL_NOUNS, WikiExtractionType.SYNT_ALL_NOUNS }, new HashSet<WikiExtractionType>()); File stopWordsFile = new File("src/test/resources/stopwords.txt"); WikiLexicalResourceIT wikiLexR = new WikiLexicalResourceIT( stopWordsFile, extractionTypes, "jdbc:mysql://nathrezim:3306/wikilexresita", "root", "nat_2k12", 0.01); // WikiLexicalResourceIT wikiLexR = new WikiLexicalResourceIT(stopWordsFile, extractionTypes, // "jdbc:mysql://hlt-services4:3306/wikilexresita","root","hlt4my2sql", 0.01); // ConfigurationFile confFile = new ConfigurationFile(new // File("B:/Apps/BIUTEE/workdir/biutee_train.xml")); // WikiLexicalResource wikiLexR = new // WikiLexicalResource(confFile.getModuleConfiguration("Wiki")); List<LexicalRule<? extends WikiRuleInfo>> rules2 = wikiLexR.getRulesForLeft(lLemma, pos2); System.out.println("Got " + rules2.size() + " for: " + lLemma + ", " + pos2); for (LexicalRule<? extends WikiRuleInfo> rule : rules2) System.out.println(rule); System.out.println(lLemma + " has " + rules2.size()); System.out.println("\n*****************************\n"); List<LexicalRule<? extends WikiRuleInfo>> otherRules = wikiLexR.getRules(lLemma, null, rLemma, null); System.out.println( "Got " + otherRules.size() + " for: " + lLemma + ", " + pos2 + ", " + rLemma + ", " + pos2); for (LexicalRule<? extends WikiRuleInfo> rule : otherRules) System.out.println(rule); System.out.println(lLemma + " and " + rLemma + " have " + otherRules.size()); // uncomment these lines to compare to the old resource - this requires you to add project // dependencies. // System.out.println("\n************************* Old Wiki **********************\n"); // // String configurationFileName = "b:/Apps/BIUTEE/workdir/biutee_train.xml"; // ConfigurationFile confFile = new ConfigurationFile(new File(configurationFileName)); // ConfigurationParams wikiModule = confFile.getModuleConfiguration("Wiki"); // // new ExperimentLoggerNeutralizer().neutralize(); // // Use the file log4j.properties to initialize log4j // PropertyConfigurator.configure("log4j.properties"); //// new LogInitializer(configurationFileName).init(); // // WikipediaLexicalRuleBase oldWiki = new WikipediaLexicalRuleBase(wikiModule); // // ImmutableSet<ac.biu.nlp.nlp.engineml.operations.rules.LexicalRule> oldRules = // oldWiki.getRules(lLemma, pos2); // System.out.println("Got "+oldRules.size() + " for: " + lLemma + ", " + pos2 ); // for (ac.biu.nlp.nlp.engineml.operations.rules.LexicalRule rule : oldRules) // System.out.println(rule); // // System.out.println(lLemma +" has " + oldRules.size() ); // System.out.println("\n*****************************\n"); }
/** * @param args * @throws LexicalResourceException * @throws UnsupportedPosTagStringException */ public static void main(String[] args) throws LexicalResourceException, UnsupportedPosTagStringException { System.out.println("Start \n*****************************\n"); String lLemma = "work"; PartOfSpeech pos2 = new BySimplerCanonicalPartOfSpeech(SimplerCanonicalPosTag.NOUN); String rLemma = "worker"; System.out.println("Looking for all rules from \"" + lLemma + "\" to \"" + rLemma + "\""); // test WN System.out.println("\nFrom the new WN:"); // WordnetLexResource wnLexR = new WordnetLexResource(new // File("//qa-srv\\Data\\RESOURCES\\WordNet\\3.0\\dict.wn.orig")); WiktionaryLexicalResource wtkLexR = new WiktionaryLexicalResource( "//qa-srv/data/RESOURCES/Wiktionary/parse", "//qa-srv/jars/stanford-postagger-2008-09-28/bidirectional-wsj-0-18.tagger"); // check for HYPERNYM, and also SYNONYM, DERIVATION Set<WiktionaryRelation> relations2 = new HashSet<WiktionaryRelation>(); relations2.addAll(Utils.arrayToCollection(WiktionaryRelation.values(), relations2)); // relations2.add(WiktionaryRelation.HYPERNYM); // relations2.add(WiktionaryRelation.DERIVED_TERM); // relations2.add(WiktionaryRelation.SYNONYM); // relations2.add(WiktionaryRelation.HYPONYM); wtkLexR.setRelationSet(relations2); // relations.add(WiktionaryRelation.PART_HOLONYM); wtkLexR.setLeftSense(WiktionaryLexicalResource.ALL_SENSES); wtkLexR.setRightSense(WiktionaryLexicalResource.ALL_SENSES); List<LexicalRule<? extends WiktionaryRuleInfo>> rules2 = wtkLexR.getRulesForLeft(lLemma, pos2); System.out.println( "Got " + rules2.size() + " for: " + lLemma + ", " + pos2 + ", " + relations2); for (LexicalRule<? extends WiktionaryRuleInfo> rule : rules2) System.out.println(rule); System.out.println( lLemma + " has " + rules2.size() + " " + relations2.toString() + " relations"); System.out.println("\n*****************************\n"); List<LexicalRule<? extends WiktionaryRuleInfo>> otherRules = wtkLexR.getRules(lLemma, null, rLemma, null); System.out.println( "Got " + otherRules.size() + " for: " + lLemma + ", " + pos2 + ", " + rLemma + ", " + pos2 + ", " + relations2); for (LexicalRule<? extends WiktionaryRuleInfo> rule : otherRules) System.out.println(rule); System.out.println( lLemma + " has " + otherRules.size() + " " + relations2.toString() + " relations"); }