Class KGvec2goClient
java.lang.Object
de.uni_mannheim.informatik.dws.melt.matching_ml.kgvec2go.KGvec2goClient
Calls the KGvec2go service.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Address of server url.private static com.google.gson.Gson
Central gson instance to parse JSON.private static org.apache.http.impl.client.CloseableHttpClient
Client to communicate with the server.private static KGvec2goClient
Instance (singleton pattern).private static boolean
Indicates whether the server has been shut down.private static final org.slf4j.Logger
Default loggerstatic final String
Protocol for requests.static final String
The URL that shall be used to perform the requests.Local vector cache. -
Constructor Summary
ModifierConstructorDescriptionprivate
Private constructor for singleton pattern. -
Method Summary
Modifier and TypeMethodDescriptionstatic Double
cosineSimilarity
(Double[] vector1, Double[] vector2) Calculates the cosine similarity between two vectors.static URI
getEncodedURI
(String path) static String
getEncodedURIString
(String path) If there is a syntax error, the givenuriString
is returned.private static Double[]
getFromBuffer
(String word, KGvec2goDatasets dataset) Look in the cache whether a vector already exists for the given word in the given dataset.static KGvec2goClient
Get the instance.getSimilarity
(String word1, String word2, KGvec2goDatasets datasets) Double[]
getVector
(String word, KGvec2goDatasets dataset) Receive a vector in the form of a double array.private static boolean
isInBuffer
(String word, KGvec2goDatasets dataset) Checks whether there is an entry for the specified word and dataset in the buffer.boolean
Simple test whether the server can be reached and is responding.void
shutDown()
Shut down the server.private boolean
Start the server.private static void
writeToBuffer
(String word, KGvec2goDatasets dataset, Double[] vector) Write in the cache whether a vector already exists for the given word in the given dataset.
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGERDefault logger -
PROTOCOL
Protocol for requests.- See Also:
-
DOMAIN
Address of server url.- See Also:
-
SERVER_URL
The URL that shall be used to perform the requests.- See Also:
-
vectorCache
Local vector cache. -
httpClient
private static org.apache.http.impl.client.CloseableHttpClient httpClientClient to communicate with the server. -
isShutDown
private static boolean isShutDownIndicates whether the server has been shut down. Initial state: shutDown. -
instance
Instance (singleton pattern). -
gson
private static com.google.gson.Gson gsonCentral gson instance to parse JSON.
-
-
Constructor Details
-
KGvec2goClient
private KGvec2goClient()Private constructor for singleton pattern.
-
-
Method Details
-
getInstance
Get the instance.- Returns:
- Client instance.
-
startServer
private boolean startServer()Start the server.- Returns:
- True in case of success, else false.
-
shutDown
public void shutDown()Shut down the server. -
isServiceAvailable
public boolean isServiceAvailable()Simple test whether the server can be reached and is responding.- Returns:
- True if server can be reached, else false.
-
getVector
Receive a vector in the form of a double array.- Parameters:
word
- Word for lookup.dataset
- Dataset for lookup.- Returns:
- Null in case of failure, else vector.
-
getSimilarity
- Parameters:
word1
- Lookup word 1.word2
- Lookup word 2.datasets
- Dataset to be used for lookup.- Returns:
- Similarity.
-
getFromBuffer
Look in the cache whether a vector already exists for the given word in the given dataset.- Parameters:
word
- for which the vector shall be looked up.dataset
- in which shall be looked.- Returns:
- Null if not in cache, else vector.
-
isInBuffer
Checks whether there is an entry for the specified word and dataset in the buffer.- Parameters:
word
- Word to be looked up.dataset
- Dataset to be used.- Returns:
- False if not in buffer, else true.
-
writeToBuffer
Write in the cache whether a vector already exists for the given word in the given dataset.- Parameters:
word
- for which the vector shall be looked up.dataset
- in which shall be looked.vector
- to be written. Null if there is no match.
-
cosineSimilarity
Calculates the cosine similarity between two vectors.- Parameters:
vector1
- First vector.vector2
- Second vector.- Returns:
- Cosine similarity as double.
-
getEncodedURI
- Throws:
URISyntaxException
-
getEncodedURIString
If there is a syntax error, the givenuriString
is returned.- Parameters:
path
- to be appended toSERVER_URL
.- Returns:
- Encoded URI as String.
-