Class MemoryMapping

  • All Implemented Interfaces:
    Serializable, IMapping

    public class MemoryMapping
    extends AMapping
    This class contains the mappings computed by an organizer. Each URI from the second knowledge base is mapped to the URI of instances from the first knowledge base and the corresponding similarity value. This is a help class for further processing that simply stores the mapping results in memory. It is important to notice that if (s, t, sim1) are already in the mapping and (s, t, sim2) is added then the mapping will contain (s, t, max(sim1, sim2))
    Version:
    Nov 24, 2015
    Author:
    Axel-C. Ngonga Ngomo (ngonga@informatik.uni-leipzig.de), Mohamed Sherif <sherif @ informatik.uni-leipzig.de>
    See Also:
    Serialized Form
    • Constructor Detail

      • MemoryMapping

        protected MemoryMapping()
    • Method Detail

      • generateRandomMapping

        public static AMapping generateRandomMapping​(int mappingSize,
                                                     int minSize,
                                                     int maxSize)
      • initReversedMap

        public void initReversedMap()
        Fills the whole content of the current map into the reversed map, which uses the similarity scores as key.
      • getSubMap

        public AMapping getSubMap​(double threshold)
        Returns a mapping that contains all elements of the current mapping that have similarity above the threshold. Basically the same as filter(mapping, threshold) but should be faster
        Specified by:
        getSubMap in class AMapping
        Parameters:
        threshold - Similarity threshold for filtering
        Returns:
        Mapping that contains all elements (s,t) with sim(s,t) < = threshold
      • add

        public void add​(String uri,
                        HashMap<String,​Double> instances)
        Add a batch of similarities to the mapping
        Specified by:
        add in class AMapping
        Parameters:
        uri - A resource from the source knowledge base
        instances - Map containing uris from the target knowledge base and their similarity to uri
      • size

        public int size()
        Specified by:
        size in class AMapping
      • add

        public void add​(String source,
                        String target,
                        double similarity)
        Add one entry to the mapping
        Specified by:
        add in class AMapping
        Parameters:
        source - Uri in the source knowledge bases
        target - Mapping uri in the target knowledge base
        similarity - Similarity of uri and mappingUri
      • getConfidence

        public double getConfidence​(String sourceInstance,
                                    String targetInstance)
        Checks whether the map contains a certain pair. If yes, its similarity is returned. Else 0 is returned
        Specified by:
        getConfidence in class AMapping
        Parameters:
        sourceInstance - Instance from the source knowledge base
        targetInstance - Instance from the target knowledge base
        Returns:
        Similarity of the two instances according to the mapping
      • contains

        public boolean contains​(String sourceInstance,
                                String targetInstance)
        Checks whether a mapping contains a particular entry
        Specified by:
        contains in class AMapping
        Parameters:
        sourceInstance - Key URI
        targetInstance - Value URI
        Returns:
        True if mapping contains (key, value), else false.
      • getNumberofMappings

        public int getNumberofMappings()
        Computes the total number of mappings contained in the object
        Specified by:
        getNumberofMappings in class AMapping
        Returns:
        Total number of mappings
      • getNumberofPositiveMappings

        public int getNumberofPositiveMappings()
        Computes the number of mappings with value greater than 0 contained in the object
        Specified by:
        getNumberofPositiveMappings in class AMapping
        Returns:
        number of mappings with value greater than 0
      • getBestOneToNMapping

        public AMapping getBestOneToNMapping()
        Computes the best one to n mapping for the current mapping, i.e., for each element of the source, it gets the best t from target. This does not mean an 1 to 1 mapping, as a t can be mapped to several s.
        Specified by:
        getBestOneToNMapping in class AMapping
        Returns:
        Best one to one mapping
      • scale

        public AMapping scale​(double d)
      • pairsOutput

        public String pairsOutput()
      • union

        public AMapping union​(AMapping other)
        Union of two maps: returns all pairs of sources s and targets t of this map and the other. The scores will be the maximum score of either this or the other.
        Parameters:
        other - , the second mapping
        Returns:
        the union of the two mappings