de.fuberlin.wiwiss.semmf.engine
Class NumericMatcher

java.lang.Object
  extended by de.fuberlin.wiwiss.semmf.engine.NumericMatcher
All Implemented Interfaces:
Matcher

public class NumericMatcher
extends java.lang.Object
implements Matcher

A class providing functionality for matching two semantically corresponding numerical values.

Version:
1.2 last modified 29.11.2006
Author:
Radoslaw Oldakowski

Field Summary
static int DEC_SIM_DOWNWARDS
           
static int DEC_SIM_UPWARDS
           
static int DEC_SIM_WITH_DEVIATION
          These constants should be used while instancing a new NumericMatcher.
private  int decreaseSim
          Setting for a particular instance of StringMatcher
private  float maxDevFraction
          For two numbers n1 nad n2, maxDevFraction is a fraction of n1 which indicates the maximum deviation from n1 beyond which the similarity between n1 and n2 eqals 0.
 
Constructor Summary
NumericMatcher(int decreaseSim, float maxDevFraction)
          Constructor.
 
Method Summary
private  float calcNumSim(float n1, float n2)
          Calculates the simiarity of two given float numbers according to the settings of this NumericMatcher.
 float calcSim(com.hp.hpl.jena.rdf.model.RDFNode queryNode, com.hp.hpl.jena.rdf.model.RDFNode resNode)
          Calculates the numeric similarity between two RDFNodes, which are Literals holding float numbers.
 int getDecreaseSimParam()
           
 float getMaxDevFraction()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEC_SIM_WITH_DEVIATION

public static final int DEC_SIM_WITH_DEVIATION
These constants should be used while instancing a new NumericMatcher. Their determine the similarity calcultion performed by a particualr NumericMatcher. These constants indicate in which direction the similarity of two different numbers should be decreased. For example, if DEC_SIM_UPWARDS is set then: - for n1 > n2, these two numbers have a similarity value = 1 - for n1 < n2, the sim value is a number inside the interval [0,1). A good example for such a case is when comparing the maximum price (n1) of a product some person is willing to pay with the actual product's price (n2). If the product's price is lower than n1 than it meets this person's expectations (therefore sim = 1), otherwise the sim decreases with increasing price (=> DEC_SIM_UPWARDS).

See Also:
Constant Field Values

DEC_SIM_UPWARDS

public static final int DEC_SIM_UPWARDS
See Also:
Constant Field Values

DEC_SIM_DOWNWARDS

public static final int DEC_SIM_DOWNWARDS
See Also:
Constant Field Values

decreaseSim

private int decreaseSim
Setting for a particular instance of StringMatcher


maxDevFraction

private float maxDevFraction
For two numbers n1 nad n2, maxDevFraction is a fraction of n1 which indicates the maximum deviation from n1 beyond which the similarity between n1 and n2 eqals 0. Example: For n1=10 and maxDevFraction=0.7 and DEC_SIM_DOWNWARDS, any value of n2 which is lower than 3 will result in sim = 0.

Constructor Detail

NumericMatcher

public NumericMatcher(int decreaseSim,
                      float maxDevFraction)
Constructor. While insstancing a NumericMatcher use the predefined constants

Parameters:
decreaseSim - indicates in which direction the similarity of two different numbers should be decreased.
maxDevFraction - for two numbers to be matched n1 nad n2, is a fraction of n1, which indicates the maximum deviation from n1 beyond which the similarity between n1 and n2 eqals 0.
Method Detail

getMaxDevFraction

public float getMaxDevFraction()
Returns:
value of the class variable maxDevFraction

getDecreaseSimParam

public int getDecreaseSimParam()
Returns:
value of the class variable decreaseSim

calcNumSim

private float calcNumSim(float n1,
                         float n2)
Calculates the simiarity of two given float numbers according to the settings of this NumericMatcher.

Parameters:
n1 - number from the query graph
n2 - number from the resource graph

calcSim

public float calcSim(com.hp.hpl.jena.rdf.model.RDFNode queryNode,
                     com.hp.hpl.jena.rdf.model.RDFNode resNode)
Calculates the numeric similarity between two RDFNodes, which are Literals holding float numbers. WARNING: This method does not validate if the passed parameters can be parsed as float's !!!

Specified by:
calcSim in interface Matcher
Parameters:
queryNode - node from the query graph
resNode - node from the resource graph
Returns:
the similarity between both nodes. The sim is a float number from [0,1]