r77971 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77970‎ | r77971 | r77972 >
Date:11:23, 7 December 2010
Author:daniel
Status:deferred
Tags:
Comment:
showProximity
Modified paths:
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/query/QueryConsole.java (modified) (history)

Diff [purge]

Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/query/QueryConsole.java
@@ -14,6 +14,8 @@
1515
1616 import de.brightbyte.data.LabeledVector;
1717 import de.brightbyte.data.cursor.DataSet;
 18+import de.brightbyte.data.measure.ScalarVectorSimilarity;
 19+import de.brightbyte.data.measure.Similarity;
1820 import de.brightbyte.db.DatabaseUtil;
1921 import de.brightbyte.io.LeveledOutput;
2022 import de.brightbyte.rdf.RdfException;
@@ -25,6 +27,7 @@
2628 import de.brightbyte.wikiword.disambig.StoredFeatureFetcher;
2729 import de.brightbyte.wikiword.disambig.StoredMeaningFetcher;
2830 import de.brightbyte.wikiword.disambig.Term;
 31+import de.brightbyte.wikiword.disambig.CoherenceDisambiguator.CoherenceDisambiguation;
2932 import de.brightbyte.wikiword.model.AbstractConceptOutput;
3033 import de.brightbyte.wikiword.model.ConceptFeatures;
3134 import de.brightbyte.wikiword.model.ConceptOutput;
@@ -47,6 +50,7 @@
4851 public class QueryConsole extends ConsoleApp<WikiWordConceptStore> {
4952
5053 protected Disambiguator disambiguator;
 54+ protected Similarity<LabeledVector<Integer>> proximityMeasure;
5155 protected ConceptQuerySpec minimalConceptSpec;
5256 protected ConceptQuerySpec resolvedConceptSpec;
5357 protected ConceptQuerySpec detailedConceptSpec;
@@ -63,6 +67,8 @@
6468 detailedConceptSpec.setIncludeDefinition(true);
6569 detailedConceptSpec.setIncludeResources(true);
6670 detailedConceptSpec.setIncludeRelations(true);
 71+
 72+ proximityMeasure = ScalarVectorSimilarity.<Integer>getInstance();
6773 }
6874
6975 protected static class ConsoleOutput {
@@ -375,11 +381,11 @@
376382 if (isGlobalThesaurus()) {
377383 String lang = params.get(1).toString();
378384 String term = params.get(2).toString();
379 - listMeaningsGlobal(lang, term, out);
 385+ listMeaningsGlobal(lang, term, out, minimalConceptSpec);
380386 }
381387 else {
382388 String term = params.get(1).toString();
383 - listMeaningsLocal(term, out);
 389+ listMeaningsLocal(term, out, minimalConceptSpec);
384390 }
385391 }
386392 else if (cmd.equals("s") || cmd.equals("cat") || cmd.equals("show")) {
@@ -408,12 +414,22 @@
409415 int id = DatabaseUtil.asInt(params.get(1));
410416 showFeatureVector(id, out);
411417 }
 418+ else if (cmd.equals("r") || cmd.equals("rel") || cmd.equals("relatedness") || cmd.equals("proximity")) {
 419+ int id1 = DatabaseUtil.asInt(params.get(1));
 420+ int id2 = DatabaseUtil.asInt(params.get(2));
 421+ showProximity(id1, id2, out);
 422+ }
 423+ else if (cmd.equals("nr") || cmd.equals("nrel") || cmd.equals("naiverelatedness") || cmd.equals("naiveproximity")) {
 424+ String n1 = params.get(1).toString();
 425+ String n2 = params.get(2).toString();
 426+ showProximity(n1, n2, out);
 427+ }
412428 else if (cmd.equals("d") || cmd.equals("dis") || cmd.equals("disambig") || cmd.equals("disambiguate")) {
413429 PhraseNode<? extends TermReference> root = getPhrases(params.get(1).toString());
414430 showDisambiguation(root, out);
415431 }
416432 else if (cmd.equals("ls") || cmd.equals("list")) {
417 - listConcepts(out);
 433+ listConcepts(out, minimalConceptSpec);
418434 }
419435 }
420436
@@ -474,18 +490,18 @@
475491 }
476492 }
477493
478 - public void listConcepts(ConsoleOutput out) throws PersistenceException {
479 - DataSet<? extends LocalConcept> meanings = getLocalConceptStore().getAllConcepts(minimalConceptSpec);
 494+ public void listConcepts(ConsoleOutput out, ConceptQuerySpec spec) throws PersistenceException {
 495+ DataSet<? extends LocalConcept> meanings = getLocalConceptStore().getAllConcepts(spec);
480496 out.writeConcepts(meanings);
481497 }
482498
483 - public void listMeaningsLocal(String term, ConsoleOutput out) throws PersistenceException {
484 - DataSet<? extends WikiWordConcept> meanings = getLocalConceptStore().getMeanings(term, resolvedConceptSpec);
 499+ public void listMeaningsLocal(String term, ConsoleOutput out, ConceptQuerySpec spec) throws PersistenceException {
 500+ DataSet<? extends WikiWordConcept> meanings = getLocalConceptStore().getMeanings(term, spec);
485501 out.writeConcepts(meanings);
486502 }
487503
488 - public void listMeaningsGlobal(String lang, String term, ConsoleOutput out) throws PersistenceException {
489 - DataSet<GlobalConcept> meanings = getGlobalConceptStore().getMeanings(lang, term, resolvedConceptSpec);
 504+ public void listMeaningsGlobal(String lang, String term, ConsoleOutput out, ConceptQuerySpec spec) throws PersistenceException {
 505+ DataSet<GlobalConcept> meanings = getGlobalConceptStore().getMeanings(lang, term, spec);
490506 out.writeConcepts(meanings);
491507 }
492508
@@ -535,6 +551,35 @@
536552 out.writeFeatureVector(conceptFeatures.getFeatureVector());
537553 }
538554
 555+ public void showProximity(String term1, String term2, ConsoleOutput out) throws PersistenceException {
 556+ List<Term> terms = new ArrayList<Term>(2);
 557+
 558+ Term t1 = new Term(term1);
 559+ Term t2 = new Term(term2);
 560+ terms.add(t1);
 561+ terms.add(t2);
 562+
 563+ CoherenceDisambiguation<Term, WikiWordConcept> r =
 564+ (CoherenceDisambiguation<Term, WikiWordConcept>) getDisambiguator().disambiguate(terms, null);
 565+
 566+ WikiWordConcept concept1 = (WikiWordConcept)r.getMeanings().get(t1);
 567+ WikiWordConcept concept2 = (WikiWordConcept)r.getMeanings().get(t2);
 568+
 569+ ConceptFeatures<WikiWordConcept, Integer> f1 = r.getFeatures().get(concept1.getId());
 570+ ConceptFeatures<WikiWordConcept, Integer> f2 = r.getFeatures().get(concept2.getId());
 571+
 572+ double d = proximityMeasure.similarity(f1.getFeatureVector(), f2.getFeatureVector());
 573+ out.write("proximity of " + concept1+" and " + concept2 + ": " + d);
 574+ }
 575+
 576+ public void showProximity(int id1, int id2, ConsoleOutput out) throws PersistenceException {
 577+ ConceptFeatures f1 = getProximityStore().getConceptFeatures(id1);
 578+ ConceptFeatures f2 = getProximityStore().getConceptFeatures(id2);
 579+
 580+ double d = proximityMeasure.similarity(f1.getFeatureVector(), f2.getFeatureVector());
 581+ out.write(d);
 582+ }
 583+
539584 public void showDisambiguation(PhraseNode<? extends TermReference> root, ConsoleOutput out) throws PersistenceException {
540585 Disambiguator.Disambiguation r = getDisambiguator().disambiguate(root, null);
541586 out.writeInterpretation(r.getMeanings());

Status & tagging log