diff --git a/src/main/java/fr/inrialpes/exmo/linkkey/utils/RedescriptionTools.java b/src/main/java/fr/inrialpes/exmo/linkkey/utils/RedescriptionTools.java index 88fcb1f2f56f87438cc6d0f116c5a6ec5b59b1c1..3fce3a2ed22eae2e6093941e7440154455714e46 100644 --- a/src/main/java/fr/inrialpes/exmo/linkkey/utils/RedescriptionTools.java +++ b/src/main/java/fr/inrialpes/exmo/linkkey/utils/RedescriptionTools.java @@ -1,8 +1,6 @@ package fr.inrialpes.exmo.linkkey.utils; -import it.unimi.dsi.fastutil.longs.Long2ObjectMap; -import it.unimi.dsi.fastutil.longs.LongOpenHashSet; -import it.unimi.dsi.fastutil.longs.LongSet; +import it.unimi.dsi.fastutil.longs.*; import java.util.Set; @@ -16,6 +14,31 @@ public class RedescriptionTools { this.p2linksIdx=p2linksIdx; } + /** + * Compute the weight of the links among a set of links + */ + public double computeWeight(long link, LongCollection linkSet) { + int a = IntPair.decodeI1(link); + int b = IntPair.decodeI2(link); + int sumA=0; + int sumB=0; + for (long l : linkSet) { + if (a==IntPair.decodeI1(l)) sumA+=1; + if (b==IntPair.decodeI2(l)) sumB+=1; + } + return 2.0/(sumA+sumB); + } + + public double[] computeWeights(LongList linkVector) { + double[] res = new double[linkVector.size()]; + int i=0; + for (long l : linkVector) { + res[i++]=computeWeight(l,linkVector); + } + return res; + } + + /** * returns the links that are associated to an expression of property pairs. * The property pair expression is given in conjunctive normal for (conjunction of disjunction)