Revision: 14550
http://gate.svn.sourceforge.net/gate/?rev=14550&view=rev
Author: valyt
Date: 2011-11-15 11:42:44 +0000 (Tue, 15 Nov 2011)
Log Message:
-----------
Bringing in the classes supporting scoring functionality from 4.x branch.
Added Paths:
-----------
mimir/trunk/mimir-core/src/gate/mimir/search/score/
mimir/trunk/mimir-core/src/gate/mimir/search/score/BindingScorer.java
mimir/trunk/mimir-core/src/gate/mimir/search/score/DelegatingScoringQueryExecutor.java
mimir/trunk/mimir-core/src/gate/mimir/search/score/MimirScorer.java
Removed Paths:
-------------
mimir/trunk/mimir-core/src/gate/mimir/search/score/BindingScorer.java
mimir/trunk/mimir-core/src/gate/mimir/search/score/DelegatingScoringQueryExecutor.java
mimir/trunk/mimir-core/src/gate/mimir/search/score/MimirScorer.java
Deleted: mimir/trunk/mimir-core/src/gate/mimir/search/score/BindingScorer.java
===================================================================
---
mimir/branches/4.x/mimir-core/src/gate/mimir/search/score/BindingScorer.java
2011-09-15 15:44:59 UTC (rev 14316)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/score/BindingScorer.java
2011-11-15 11:42:44 UTC (rev 14550)
@@ -1,72 +0,0 @@
-package gate.mimir.search.score;
-
-import gate.mimir.search.query.Binding;
-import gate.mimir.search.query.QueryExecutor;
-import it.unimi.dsi.mg4j.index.Index;
-import it.unimi.dsi.mg4j.search.DocumentIterator;
-import it.unimi.dsi.mg4j.search.score.AbstractWeightedScorer;
-import it.unimi.dsi.mg4j.search.score.Scorer;
-
-import java.io.IOException;
-
-public class BindingScorer extends AbstractWeightedScorer implements
MimirScorer {
- public BindingScorer() {
- this(16, 0.9);
- }
-
-
- public BindingScorer(int h, double alpha) {
- super();
- this.h = h;
- this.alpha = alpha;
- }
-
- @Override
- public double score(Index index) throws IOException {
- return score();
- }
-
- @Override
- public double score() throws IOException {
- double score= 0.0;
- Binding aHit = nextHit();
- while(aHit != null) {
- int length = aHit.getLength();
- score += length < h ? 1 : Math.pow((double)h / length, alpha);
- aHit = nextHit();
- }
- return score;
- }
-
- @Override
- public boolean usesIntervals() {
- return true;
- }
-
- @Override
- public BindingScorer copy() {
- return new BindingScorer();
- }
-
- @Override
- public void wrap(DocumentIterator documentIterator) throws IOException {
- super.wrap(documentIterator);
- this.underlyingExecutor = (QueryExecutor)documentIterator;
- }
-
- protected QueryExecutor underlyingExecutor;
-
- protected int h;
-
- protected double alpha;
-
- public int nextDocument(int greaterThan) throws IOException {
- return underlyingExecutor.nextDocument(greaterThan);
- }
-
- public Binding nextHit() throws IOException {
- return underlyingExecutor.nextHit();
- }
-
-
-}
Copied: mimir/trunk/mimir-core/src/gate/mimir/search/score/BindingScorer.java
(from rev 14316,
mimir/branches/4.x/mimir-core/src/gate/mimir/search/score/BindingScorer.java)
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/score/BindingScorer.java
(rev 0)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/score/BindingScorer.java
2011-11-15 11:42:44 UTC (rev 14550)
@@ -0,0 +1,85 @@
+/*
+ * BindingScorer.java
+ *
+ * Copyright (c) 2007-2011, The University of Sheffield.
+ *
+ * This file is part of GATE Mímir (see http://gate.ac.uk/family/mimir.html),
+ * and is free software, licenced under the GNU Lesser General Public License,
+ * Version 3, June 2007 (also included with this distribution as file
+ * LICENCE-LGPL3.html).
+ *
+ * Valentin Tablan, 14 September 2011
+ *
+ * $Id$
+ */
+package gate.mimir.search.score;
+
+import gate.mimir.search.query.Binding;
+import gate.mimir.search.query.QueryExecutor;
+import it.unimi.dsi.mg4j.index.Index;
+import it.unimi.dsi.mg4j.search.DocumentIterator;
+import it.unimi.dsi.mg4j.search.score.AbstractWeightedScorer;
+
+import java.io.IOException;
+
+public class BindingScorer extends AbstractWeightedScorer implements
MimirScorer {
+ public BindingScorer() {
+ this(16, 0.9);
+ }
+
+
+ public BindingScorer(int h, double alpha) {
+ super();
+ this.h = h;
+ this.alpha = alpha;
+ }
+
+ @Override
+ public double score(Index index) throws IOException {
+ return score();
+ }
+
+ @Override
+ public double score() throws IOException {
+ double score= 0.0;
+ Binding aHit = nextHit();
+ while(aHit != null) {
+ int length = aHit.getLength();
+ score += length < h ? 1 : Math.pow((double)h / length, alpha);
+ aHit = nextHit();
+ }
+ return score;
+ }
+
+ @Override
+ public boolean usesIntervals() {
+ return true;
+ }
+
+ @Override
+ public BindingScorer copy() {
+ return new BindingScorer();
+ }
+
+ @Override
+ public void wrap(DocumentIterator documentIterator) throws IOException {
+ super.wrap(documentIterator);
+ this.underlyingExecutor = (QueryExecutor)documentIterator;
+ }
+
+ protected QueryExecutor underlyingExecutor;
+
+ protected int h;
+
+ protected double alpha;
+
+ public int nextDocument(int greaterThan) throws IOException {
+ return underlyingExecutor.nextDocument(greaterThan);
+ }
+
+ public Binding nextHit() throws IOException {
+ return underlyingExecutor.nextHit();
+ }
+
+
+}
Deleted:
mimir/trunk/mimir-core/src/gate/mimir/search/score/DelegatingScoringQueryExecutor.java
===================================================================
---
mimir/branches/4.x/mimir-core/src/gate/mimir/search/score/DelegatingScoringQueryExecutor.java
2011-09-15 15:44:59 UTC (rev 14316)
+++
mimir/trunk/mimir-core/src/gate/mimir/search/score/DelegatingScoringQueryExecutor.java
2011-11-15 11:42:44 UTC (rev 14550)
@@ -1,110 +0,0 @@
-package gate.mimir.search.score;
-
-import gate.mimir.search.query.Binding;
-import gate.mimir.search.query.QueryExecutor;
-import it.unimi.dsi.fastutil.objects.Reference2DoubleMap;
-import it.unimi.dsi.mg4j.index.Index;
-import it.unimi.dsi.mg4j.search.DocumentIterator;
-import it.unimi.dsi.mg4j.search.score.DelegatingScorer;
-import it.unimi.dsi.mg4j.search.score.Scorer;
-
-import java.io.IOException;
-
-
-public class DelegatingScoringQueryExecutor implements MimirScorer {
-
- public DelegatingScoringQueryExecutor(DelegatingScorer scorer)
- throws IOException {
- this.underlyingScorer = scorer;
- }
-
- public int nextDocument(int greaterThan) throws IOException {
- return underlyingExecutor.nextDocument(greaterThan);
- }
-
-
- /* (non-Javadoc)
- * @see gate.mimir.search.query.MimirScorer#nextHit()
- */
- @Override
- public Binding nextHit() throws IOException {
- return underlyingExecutor.nextHit();
- }
-
-
-
-
- public double score() throws IOException {
- return underlyingScorer.score();
- }
-
-
- private DelegatingScorer underlyingScorer;
-
- private QueryExecutor underlyingExecutor;
-
- public boolean hasNext() {
- return underlyingScorer.hasNext();
- }
-
- public Integer next() {
- return underlyingScorer.next();
- }
-
-
-
- public void remove() {
- underlyingScorer.remove();
- }
-
-
-
- public double score(Index index) throws IOException {
- return underlyingScorer.score(index);
- }
-
- public boolean setWeights(Reference2DoubleMap<Index> index2Weight) {
- return underlyingScorer.setWeights(index2Weight);
- }
-
-
-
- public Reference2DoubleMap<Index> getWeights() {
- return underlyingScorer.getWeights();
- }
-
-
- @Deprecated
- public int nextInt() {
- return underlyingScorer.nextInt();
- }
-
-
-
- public int nextDocument() throws IOException {
- return underlyingScorer.nextDocument();
- }
-
-
-
- public DelegatingScorer copy() {
- try {
- return new DelegatingScoringQueryExecutor(underlyingScorer.copy());
- } catch(IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- public int skip(int arg0) {
- return underlyingScorer.skip(arg0);
- }
-
- public void wrap(DocumentIterator queryExecutor) throws IOException {
- underlyingExecutor = (QueryExecutor)queryExecutor;
- underlyingScorer.wrap(queryExecutor);
- }
-
- public boolean usesIntervals() {
- return underlyingScorer.usesIntervals();
- }
-}
Copied:
mimir/trunk/mimir-core/src/gate/mimir/search/score/DelegatingScoringQueryExecutor.java
(from rev 14316,
mimir/branches/4.x/mimir-core/src/gate/mimir/search/score/DelegatingScoringQueryExecutor.java)
===================================================================
---
mimir/trunk/mimir-core/src/gate/mimir/search/score/DelegatingScoringQueryExecutor.java
(rev 0)
+++
mimir/trunk/mimir-core/src/gate/mimir/search/score/DelegatingScoringQueryExecutor.java
2011-11-15 11:42:44 UTC (rev 14550)
@@ -0,0 +1,123 @@
+/*
+ * DelegatingScoringQueryExecutor.java
+ *
+ * Copyright (c) 2007-2011, The University of Sheffield.
+ *
+ * This file is part of GATE Mímir (see http://gate.ac.uk/family/mimir.html),
+ * and is free software, licenced under the GNU Lesser General Public License,
+ * Version 3, June 2007 (also included with this distribution as file
+ * LICENCE-LGPL3.html).
+ *
+ * Valentin Tablan, 14 September 2011
+ *
+ * $Id$
+ */
+package gate.mimir.search.score;
+
+import gate.mimir.search.query.Binding;
+import gate.mimir.search.query.QueryExecutor;
+import it.unimi.dsi.fastutil.objects.Reference2DoubleMap;
+import it.unimi.dsi.mg4j.index.Index;
+import it.unimi.dsi.mg4j.search.DocumentIterator;
+import it.unimi.dsi.mg4j.search.score.DelegatingScorer;
+
+import java.io.IOException;
+
+
+public class DelegatingScoringQueryExecutor implements MimirScorer {
+
+ public DelegatingScoringQueryExecutor(DelegatingScorer scorer)
+ throws IOException {
+ this.underlyingScorer = scorer;
+ }
+
+ public int nextDocument(int greaterThan) throws IOException {
+ return underlyingExecutor.nextDocument(greaterThan);
+ }
+
+
+ /* (non-Javadoc)
+ * @see gate.mimir.search.query.MimirScorer#nextHit()
+ */
+ @Override
+ public Binding nextHit() throws IOException {
+ return underlyingExecutor.nextHit();
+ }
+
+
+
+
+ public double score() throws IOException {
+ return underlyingScorer.score();
+ }
+
+
+ private DelegatingScorer underlyingScorer;
+
+ private QueryExecutor underlyingExecutor;
+
+ public boolean hasNext() {
+ return underlyingScorer.hasNext();
+ }
+
+ public Integer next() {
+ return underlyingScorer.next();
+ }
+
+
+
+ public void remove() {
+ underlyingScorer.remove();
+ }
+
+
+
+ public double score(Index index) throws IOException {
+ return underlyingScorer.score(index);
+ }
+
+ public boolean setWeights(Reference2DoubleMap<Index> index2Weight) {
+ return underlyingScorer.setWeights(index2Weight);
+ }
+
+
+
+ public Reference2DoubleMap<Index> getWeights() {
+ return underlyingScorer.getWeights();
+ }
+
+
+ @Deprecated
+ public int nextInt() {
+ return underlyingScorer.nextInt();
+ }
+
+
+
+ public int nextDocument() throws IOException {
+ return underlyingScorer.nextDocument();
+ }
+
+
+
+ public DelegatingScorer copy() {
+ try {
+ return new DelegatingScoringQueryExecutor(underlyingScorer.copy());
+ } catch(IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public int skip(int arg0) {
+ return underlyingScorer.skip(arg0);
+ }
+
+ public void wrap(DocumentIterator queryExecutor) throws IOException {
+ underlyingExecutor = (QueryExecutor)queryExecutor;
+ underlyingScorer.wrap(queryExecutor);
+ }
+
+ public boolean usesIntervals() {
+ return underlyingScorer.usesIntervals();
+ }
+}
Deleted: mimir/trunk/mimir-core/src/gate/mimir/search/score/MimirScorer.java
===================================================================
--- mimir/branches/4.x/mimir-core/src/gate/mimir/search/score/MimirScorer.java
2011-09-15 15:44:59 UTC (rev 14316)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/score/MimirScorer.java
2011-11-15 11:42:44 UTC (rev 14550)
@@ -1,23 +0,0 @@
-package gate.mimir.search.score;
-
-import gate.mimir.search.query.Binding;
-import gate.mimir.search.query.QueryExecutor;
-import it.unimi.dsi.mg4j.search.DocumentIterator;
-import it.unimi.dsi.mg4j.search.score.DelegatingScorer;
-
-import java.io.IOException;
-
-public interface MimirScorer extends DelegatingScorer {
- public abstract Binding nextHit() throws IOException;
-
-
- /**
- * The DocumentIterator provided <b>must</b> be a {@link QueryExecutor}.
- */
- @Override
- public void wrap(DocumentIterator queryExecutor) throws IOException;
-
-
- public int nextDocument(int greaterThan) throws IOException;
-
-}
\ No newline at end of file
Copied: mimir/trunk/mimir-core/src/gate/mimir/search/score/MimirScorer.java
(from rev 14316,
mimir/branches/4.x/mimir-core/src/gate/mimir/search/score/MimirScorer.java)
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/score/MimirScorer.java
(rev 0)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/score/MimirScorer.java
2011-11-15 11:42:44 UTC (rev 14550)
@@ -0,0 +1,37 @@
+/*
+ * MimirScorer.java
+ *
+ * Copyright (c) 2007-2011, The University of Sheffield.
+ *
+ * This file is part of GATE Mímir (see http://gate.ac.uk/family/mimir.html),
+ * and is free software, licenced under the GNU Lesser General Public License,
+ * Version 3, June 2007 (also included with this distribution as file
+ * LICENCE-LGPL3.html).
+ *
+ * Valentin Tablan, 14 September 2011
+ *
+ * $Id$
+ */
+package gate.mimir.search.score;
+
+import gate.mimir.search.query.Binding;
+import gate.mimir.search.query.QueryExecutor;
+import it.unimi.dsi.mg4j.search.DocumentIterator;
+import it.unimi.dsi.mg4j.search.score.DelegatingScorer;
+
+import java.io.IOException;
+
+public interface MimirScorer extends DelegatingScorer {
+ public abstract Binding nextHit() throws IOException;
+
+
+ /**
+ * The DocumentIterator provided <b>must</b> be a {@link QueryExecutor}.
+ */
+ @Override
+ public void wrap(DocumentIterator queryExecutor) throws IOException;
+
+
+ public int nextDocument(int greaterThan) throws IOException;
+
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs