Package org.aksw.limes.core.io.cache
Class HybridCache
- java.lang.Object
-
- org.aksw.limes.core.io.cache.ACache
-
- org.aksw.limes.core.io.cache.MemoryCache
-
- org.aksw.limes.core.io.cache.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
-
-
Field Summary
Fields Modifier and Type Field Description protected Iterator<Instance>instanceIteratorprotected TreeMap<String,Instance>instanceMap
-
Constructor Summary
Constructors Constructor Description HybridCache()HybridCache(File folder)Create cache specifying the parent folder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddInstance(Instance i)voidaddTriple(String s, String p, String o)Adds a new spo statement to the cachebooleancontainsInstance(Instance i)booleancontainsUri(String uri)ArrayList<Instance>getAllInstances()Returns all the instance contained in the cacheArrayList<String>getAllUris()static HybridCachegetData(File folder, KBInfo kb)Method to get Data of the specified endpoint, and cache it to the "cache" folder in the folder specified.static HybridCachegetData(KBInfo kb)FilegetFolder()Returns the file pointing to the parent folder of cache.InstancegetInstance(String uri)InstancegetNextInstance()Returns the next instance in the list of instancesstatic HybridCachegetNoPrefixData(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.static HybridCachegetNoPrefixData(KBInfo kb)This method is used by learners which do not have prefix information.static HybridCacheloadFromFile(File file)Tries to load the content of the cache from a filevoidresetIterator()voidsaveToFile(File file)Tries to serialize the content of the cache to a file.voidsetFolder(File folder)Set the parent folder of the cache sub folder.intsize()StringtoString()-
Methods inherited from class org.aksw.limes.core.io.cache.MemoryCache
addProperty, clone, equals, getAllProperties, getSample, hashCode, parseCSVtoRDFModel, replaceInstance
-
-
-
-
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(KBInfo kb)
-
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:
getNextInstancein classMemoryCache- Returns:
- null if no next instance, else the next instance
-
getAllInstances
public ArrayList<Instance> getAllInstances()
Returns all the instance contained in the cache- Overrides:
getAllInstancesin classMemoryCache- Returns:
- ArrayList containing all instances
-
addInstance
public void addInstance(Instance i)
- Overrides:
addInstancein classMemoryCache
-
getInstance
public Instance getInstance(String uri)
- Overrides:
getInstancein classMemoryCache- 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:
sizein classMemoryCache- 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:
addTriplein classMemoryCache- Parameters:
s- The URI of the instance linked to o via pp- The property which links s and oo- The value of the property of p for the entity s
-
containsUri
public boolean containsUri(String uri)
- Overrides:
containsUriin classMemoryCache- Parameters:
uri- The URI to looks for- Returns:
- True if an instance with the URI uri is found in the cache, else false
-
resetIterator
public void resetIterator()
- Overrides:
resetIteratorin classMemoryCache
-
toString
public String toString()
- Overrides:
toStringin classMemoryCache
-
getAllUris
public ArrayList<String> getAllUris()
- Overrides:
getAllUrisin classMemoryCache
-
containsInstance
public boolean containsInstance(Instance i)
- Overrides:
containsInstancein classMemoryCache- 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.
-
-