Class HybridCache

  • All Implemented Interfaces:
    Serializable, ICache

    public class HybridCache
    extends MemoryCache
    implements Serializable
    This cache implements a hybrid between memory and file cache. It generates a hash for each data source associated with it and serializes the content of the corresponding data source into a file. If another mapping task is associated with the same data source, it retrieves the corresponding data from the file, which is obviously more efficient for online data sources (no HTTP latency, offline processing, etc.). Else, it retrieves the data, generates a hash and caches it on the hard drive. Enhancing it with folders: specify the folder, where the application has permissions to read and write files.
    Version:
    Jul 8, 2016
    Author:
    Axel-C. Ngonga Ngomo (ngonga@informatik.uni-leipzig.de), Lyko, Mohamed Sherif (sherif@informatik.uni-leipzig.de)
    See Also:
    Serialized Form
    • Constructor Detail

      • HybridCache

        public HybridCache()
      • HybridCache

        public HybridCache​(File folder)
        Create cache specifying the parent folder. Make shure the Application has write permissions there.
        Parameters:
        folder - File pointing to the the parent folder of the (to-be-created) "cache" folder.
    • Method Detail

      • loadFromFile

        public static HybridCache loadFromFile​(File file)
                                        throws IOException
        Tries to load the content of the cache from a file
        Parameters:
        file - File from which the content is to be loaded
        Returns:
        A Hybrid cache
        Throws:
        IOException - if file not found
      • getData

        public static HybridCache getData​(File folder,
                                          KBInfo kb)
        Method to get Data of the specified endpoint, and cache it to the "cache" folder in the folder specified.
        Parameters:
        folder - Path to the parent folder of the "cache" folder.
        kb - Endpoint specification.
        Returns:
        HybridCache of the data
      • getNoPrefixData

        public static HybridCache getNoPrefixData​(KBInfo kb)
        This method is used by learners which do not have prefix information.
        Parameters:
        kb - Info to the knowledge base to query
        Returns:
        A cache filled with the entities to link
      • getNoPrefixData

        public static HybridCache getNoPrefixData​(File folder,
                                                  KBInfo kb)
        This method is used by learners which do not have prefix information and with a specified folder containing the cache folder.
        Parameters:
        folder - Path to parent folder of the supposed cache folder.
        kb - Info to the knowledge base to query
        Returns:
        A cache filled with the entities to link
      • getNextInstance

        public Instance getNextInstance()
        Returns the next instance in the list of instances
        Overrides:
        getNextInstance in class MemoryCache
        Returns:
        null if no next instance, else the next instance
      • getInstance

        public Instance getInstance​(String uri)
        Overrides:
        getInstance in class MemoryCache
        Parameters:
        uri - URI to look for
        Returns:
        The instance with the URI uri if it is in the cache, else null
      • size

        public int size()
        Overrides:
        size in class MemoryCache
        Returns:
        The size of the cache
      • addTriple

        public void addTriple​(String s,
                              String p,
                              String o)
        Adds a new spo statement to the cache
        Overrides:
        addTriple in class MemoryCache
        Parameters:
        s - The URI of the instance linked to o via p
        p - The property which links s and o
        o - The value of the property of p for the entity s
      • containsUri

        public boolean containsUri​(String uri)
        Overrides:
        containsUri in class MemoryCache
        Parameters:
        uri - The URI to looks for
        Returns:
        True if an instance with the URI uri is found in the cache, else false
      • containsInstance

        public boolean containsInstance​(Instance i)
        Overrides:
        containsInstance in class MemoryCache
        Parameters:
        i - The instance to look for
        Returns:
        true if the URI of the instance is found in the cache
      • saveToFile

        public void saveToFile​(File file)
        Tries to serialize the content of the cache to a file. If it fails, no file is written to avoid the corruption of future data sources.
        Parameters:
        file - File wherein the content of the cache is to be serialized
      • getFolder

        public File getFolder()
        Returns the file pointing to the parent folder of cache.
        Returns:
        File folder
      • setFolder

        public void setFolder​(File folder)
        Set the parent folder of the cache sub folder.
        Parameters:
        folder - Pointing to the parent folder holding the cache.