@Override protected List<Double> computeRelatedness(Page page1,Page page2) throws WikiApiException {
  List<Double> relatednessValues=new ArrayList<Double>();
  Set<Category> categories1=relatednessUtilities.getCategories(page1);
  Set<Category> categories2=relatednessUtilities.getCategories(page2);
  if (categories1 == null || categories2 == null) {
    return null;
  }
  double depthOfHierarchy=catGraph.getDepth();
  if (depthOfHierarchy == 0) {
    logger.info("The depth of the hierarchy is 0. Cannot compute LeacockChodorow relatedness.");
    return null;
  }
  for (  Category cat1 : categories1) {
    for (    Category cat2 : categories2) {
      int pathLength=catGraph.getTaxonomicallyBoundPathLengthInEdges(cat1,cat2);
      if (pathLength < 0) {
        continue;
      }
      double relatedness=Math.log((2 * depthOfHierarchy) / (pathLength + 1));
      relatednessValues.add(relatedness);
    }
  }
  return relatednessValues;
}

@ Override protected List < Double > computeRelatedness ( Page page1 , Page page2 ) throws WikiApiException { List < Double > relatednessValues = new ArrayList < Double > ( ) ; Set < Category > categories1 = relatednessUtilities . getCategories ( page1 ) ; Set < Category > categories2 = relatednessUtilities . getCategories ( page2 ) ; if ( categories1 == null || categories2 == null ) { return null ; } double depthOfHierarchy = catGraph . getDepth ( ) ; if ( depthOfHierarchy == 0 ) { logger . info ( "The depth of the hierarchy is 0. Cannot compute LeacockChodorow relatedness." ) ; return null ; } for ( Category cat1 : categories1 ) { for ( Category cat2 : categories2 ) { int pathLength = catGraph . getTaxonomicallyBoundPathLengthInEdges ( cat1 , cat2 ) ; if ( pathLength < 0 ) { continue ; } double relatedness = Math . log ( ( 2 * depthOfHierarchy ) / ( pathLength + 1 ) ) ; relatednessValues . add ( relatedness ) ; } } return relatednessValues ; }
implements the distance measure by leacock and chodorow ( 1998 ) lch ( c1 , c2 ) = - log ( minpathlength ( c1 , c2 ) / 2 * depth of the hierarchy ) lch ( c1 , c2 ) = - log ( minpl ( c1 , c2 ) / 2 * depth ) = log ( 2 * depth / minpl ( c1 , c2 ) ) minpathlength is measured in nodes , i . e . the distance of a node to itself is 0 ! this would cause a logarithm error ( or a division by zero ) ) . thus we changed the behaviour in order to return a distance of 1 , if the nodes are equal or neighbors .
