Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 7df85789 authored by Adrien's avatar Adrien
Browse files

new comments & javadoc

parent 09d49a23
No related branches found
No related tags found
No related merge requests found
...@@ -4,50 +4,50 @@ import java.util.HashMap; ...@@ -4,50 +4,50 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* The Distribution class manages a collections of Objects and their associated values. * The Distribution class manages a collections of ontologies and their associated values.
*/ */
public class Distribution { public class Distribution {
private Map<Object, Integer> objectMap; private Map<Object, Double> objectMap;
/** /**
* Initialization * Constructor for the Distribution class. Initalize objectMap.
*/ */
public Distribution() { public Distribution() {
this.objectMap = new HashMap<>(); this.objectMap = new HashMap<>();
} }
/** /**
* Adds an object with an associated integer value. * Adds an ontology with an associated integer value.
* @param obj The object to store. * @param cat The ontology to store.
* @param value The integer value associated with the object. * @param value The integer value associated with the object.
*/ */
public void addObject(Object obj, int value) { public void addObject(Object cat, Double value) {
objectMap.put(obj, value); objectMap.put(cat, value);
} }
/** /**
* Retrieves the value of a given object. * Retrieves the value of a given ontology.
* @param obj The object to look up. * @param cat The object to look up.
* @return The associated integer value, or null if not found. * @return The associated integer value, or null if not found.
*/ */
public Integer getValue(Object obj) { public Double getValue(Object cat) {
return objectMap.getOrDefault(obj, null); return objectMap.getOrDefault(cat, null);
} }
/** /**
* Checks if the object exists in the distribution. * Checks if the ontology exists in the distribution.
* @param obj The object to check. * @param cat The ontology/caterogy to check.
* @return True if the object exists, false otherwise. * @return True if the ontology exists, false otherwise.
*/ */
public boolean contains(Object obj) { public boolean contains(Object cat) {
return objectMap.containsKey(obj); return objectMap.containsKey(cat);
} }
/** /**
* Gets the entire distribution as a HashMap. * Gets the entire distribution as a HashMap.
* @return The HashMap storing object-value pairs. * @return The HashMap storing categories-value pairs.
*/ */
public Map<Object, Integer> getObjectMap() { public Map<Object, Double> getObjectMap() {
return objectMap; return objectMap;
} }
......
...@@ -7,18 +7,28 @@ import java.util.Optional; ...@@ -7,18 +7,28 @@ import java.util.Optional;
class DoubleMapSimilarity<T> implements Similarity<T> { class DoubleMapSimilarity<T> implements Similarity<T> {
private final Map<T, Map<T, Double>> similarityMap = new HashMap<>(); private final Map<T, Map<T, Double>> similarityMap = new HashMap<>();
public void addSimilarity(T obj1, T obj2, double similarity) { /**
similarityMap.computeIfAbsent(obj1, k -> new HashMap<>()).put(obj2, similarity); * Adds a similarity between two objects in the similarity map.
* @param cat1
* @param cat2
* @param similarity
*/
public void addSimilarity(T cat1, T cat2, double similarity) {
similarityMap.computeIfAbsent(cat1, k -> new HashMap<>()).put(cat2, similarity);
similarityMap.computeIfAbsent(obj2, k -> new HashMap<>()) .put(obj1, similarity); //Symmetry of similarity similarityMap.computeIfAbsent(cat2, k -> new HashMap<>()).put(cat1, similarity); //Symmetry of the distance
} }
/**
* Retrieves the similarity between two objects.
* @param cat1
* @param cat2
*/
@Override @Override
public Double getSimilarity(Object obj1, Object obj2) { public Double getSimilarity(Object cat1, Object cat2) {
if (obj1 instanceof String && obj2 instanceof String) { if (cat1.getClass().equals( cat2.getClass())) {
return Optional.ofNullable(similarityMap.get(obj1)).map(m -> m.get(obj2)).orElse(0.0); return Optional.ofNullable(similarityMap.get(cat1)).map(m -> m.get(cat2)).orElse(0.0);
} }
return null; //Return 0.0 if no similarity is found return null; //Return 0.0 if no similarity is found (But for now it return null if cat1.class != cat2.class)
} }
} }
\ No newline at end of file
...@@ -2,16 +2,20 @@ package kdiv; ...@@ -2,16 +2,20 @@ package kdiv;
import java.util.Map; import java.util.Map;
public class Main { public class Main {
static final String UNSTRUCT = "unstructdist"; static final String UNSTRUCT = "unstructdist";
static final String LINEAR = "linearstructdist"; static final String LINEAR = "linearstructdist";
static final String GRAPHSEM = "graphsemdistinit"; static final String GRAPHSEM = "graphsemdistinit";
static final String NAMESEM = "namesemdistinit"; static final String NAMESEM = "namesemdistinit";
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
/*
* Pseudo test :
* - Initialize a sample distribution
* - Create a sampleDistnce with a distance matrix
* - Compute the diversity with q = i
*/
Sample samp = new Sample(); Sample samp = new Sample();
Map<String, Double> distrib = samp.createSampleDistribution(); Map<String, Double> distrib = samp.createSampleDistribution();
DoubleMapSimilarity<String> similarity = samp.createSampleDistance(GRAPHSEM); DoubleMapSimilarity<String> similarity = samp.createSampleDistance(GRAPHSEM);
......
...@@ -5,7 +5,13 @@ package kdiv; ...@@ -5,7 +5,13 @@ package kdiv;
*/ */
public interface Similarity<T> { public interface Similarity<T> {
Double getSimilarity(T obj1, T obj2); /**
* Get the similarity between cat1 and cat2.
* @param cat1
* @param cat2
* @return
*/
Double getSimilarity(T cat1, T cat2);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment