java.lang.Object
de.uni_mannheim.informatik.dws.melt.matching_ml.kgvec2go.KGvec2goClient

public class KGvec2goClient extends Object
Calls the KGvec2go service.
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
      Default logger
    • PROTOCOL

      public static final String PROTOCOL
      Protocol for requests.
      See Also:
    • DOMAIN

      public static final String DOMAIN
      Address of server url.
      See Also:
    • SERVER_URL

      public static final String SERVER_URL
      The URL that shall be used to perform the requests.
      See Also:
    • vectorCache

      private static HashMap<String,Double[]> vectorCache
      Local vector cache.
    • httpClient

      private static org.apache.http.impl.client.CloseableHttpClient httpClient
      Client to communicate with the server.
    • isShutDown

      private static boolean isShutDown
      Indicates whether the server has been shut down. Initial state: shutDown.
    • instance

      private static KGvec2goClient instance
      Instance (singleton pattern).
    • gson

      private static com.google.gson.Gson gson
      Central gson instance to parse JSON.
  • Constructor Details

    • KGvec2goClient

      private KGvec2goClient()
      Private constructor for singleton pattern.
  • Method Details

    • getInstance

      public static KGvec2goClient 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

      public Double[] getVector(String word, KGvec2goDatasets dataset)
      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

      public Double getSimilarity(String word1, String word2, KGvec2goDatasets datasets)
      Parameters:
      word1 - Lookup word 1.
      word2 - Lookup word 2.
      datasets - Dataset to be used for lookup.
      Returns:
      Similarity.
    • getFromBuffer

      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.
      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

      private static boolean isInBuffer(String word, KGvec2goDatasets dataset)
      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

      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.
      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

      public static Double cosineSimilarity(Double[] vector1, Double[] vector2)
      Calculates the cosine similarity between two vectors.
      Parameters:
      vector1 - First vector.
      vector2 - Second vector.
      Returns:
      Cosine similarity as double.
    • getEncodedURI

      public static URI getEncodedURI(String path) throws URISyntaxException
      Throws:
      URISyntaxException
    • getEncodedURIString

      public static String getEncodedURIString(String path)
      If there is a syntax error, the given uriString is returned.
      Parameters:
      path - to be appended to SERVER_URL.
      Returns:
      Encoded URI as String.