Class KGvec2goClient
java.lang.Object
de.uni_mannheim.informatik.dws.melt.matching_ml.kgvec2go.KGvec2goClient
Calls the KGvec2go service.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringAddress of server url.private static com.google.gson.GsonCentral gson instance to parse JSON.private static org.apache.http.impl.client.CloseableHttpClientClient to communicate with the server.private static KGvec2goClientInstance (singleton pattern).private static booleanIndicates whether the server has been shut down.private static final org.slf4j.LoggerDefault loggerstatic final StringProtocol for requests.static final StringThe URL that shall be used to perform the requests.Local vector cache. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor for singleton pattern. -
Method Summary
Modifier and TypeMethodDescriptionstatic DoublecosineSimilarity(Double[] vector1, Double[] vector2) Calculates the cosine similarity between two vectors.static URIgetEncodedURI(String path) static StringgetEncodedURIString(String path) If there is a syntax error, the givenuriStringis 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 KGvec2goClientGet 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 booleanisInBuffer(String word, KGvec2goDatasets dataset) Checks whether there is an entry for the specified word and dataset in the buffer.booleanSimple test whether the server can be reached and is responding.voidshutDown()Shut down the server.private booleanStart the server.private static voidwriteToBuffer(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 givenuriStringis returned.- Parameters:
path- to be appended toSERVER_URL.- Returns:
- Encoded URI as String.
-