Class Neo4JServlet

java.lang.Object
org.qubitpi.wilhelm.web.endpoints.Neo4JServlet

@Singleton @Immutable @ThreadSafe @Path("/neo4j") @Produces("application/json") public class Neo4JServlet extends Object
Endpoint that contains a basic sanity-check.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for dependency injection.
  • Method Summary

    Modifier and Type
    Method
    Description
    jakarta.ws.rs.core.Response
    expand(@NotNull String word)
    Recursively find all related terms and definitions of a word.
    jakarta.ws.rs.core.Response
    expandApoc(@NotNull String word, @NotNull String maxHops)
    Recursively find all related terms and definitions of a word using a single Cypher query with apoc extension.
    jakarta.ws.rs.core.Response
    expandDfs(@NotNull String word)
    Recursively find all related terms and definitions of a word using multiple Cypher queries with a plain BFS algorithm.
    jakarta.ws.rs.core.Response
    getCountByLanguage(@NotNull String language)
    Returns the total number of terms of a specified langauges.
    jakarta.ws.rs.core.Response
    getVocabularyByLanguagePaged(@NotNull String language, @NotNull String perPage, @NotNull String page)
    Get paginated vocabularies of a language.
    jakarta.ws.rs.core.Response
    search(@NotNull String keyword)
    Search all nodes whose label contains a specified keyword.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Neo4JServlet

      @Inject public Neo4JServlet()
      Constructor for dependency injection.
  • Method Details

    • getCountByLanguage

      @GET @Path("/languages/{language}/count") @Produces("application/json") public jakarta.ws.rs.core.Response getCountByLanguage(@NotNull @PathParam("language") @NotNull String language)
      Returns the total number of terms of a specified langauges.
      Parameters:
      language - The language. Must be one of the valid return value of Language.getPathName(); otherwise a 400 response is returned
      Returns:
      a list of one map entry, whose key is 'count' and value is the total
    • getVocabularyByLanguagePaged

      @GET @Path("/languages/{language}") @Produces("application/json") public jakarta.ws.rs.core.Response getVocabularyByLanguagePaged(@NotNull @PathParam("language") @NotNull String language, @NotNull @QueryParam("perPage") @NotNull String perPage, @NotNull @QueryParam("page") @NotNull String page)
      Get paginated vocabularies of a language.
      Parameters:
      language - The language. Must be one of the valid return value of Language.getPathName(); otherwise a 400 response is returned
      perPage - Requested number of words to be displayed on each page of results
      page - Requested page of results desired
      Returns:
      the paginated Neo4J query results in JSON format
    • search

      @GET @Path("/search/{keyword}") @Produces("application/json") public jakarta.ws.rs.core.Response search(@NotNull @PathParam("keyword") @NotNull String keyword)
      Search all nodes whose label contains a specified keyword.
      Parameters:
      keyword - The provided keyword
      Returns:
      all nodes whose "label" attribute contains the search keyword
    • expand

      @GET @Path("/expand/{word}") @Produces("application/json") public jakarta.ws.rs.core.Response expand(@NotNull @PathParam("word") @NotNull String word)
      Recursively find all related terms and definitions of a word.
      Parameters:
      word - The word to expand
      Returns:
      a JSON representation of the expanded sub-graph
    • expandDfs

      @GET @Path("/expandDfs/{word}") @Produces("application/json") public jakarta.ws.rs.core.Response expandDfs(@NotNull @PathParam("word") @NotNull String word)
      Recursively find all related terms and definitions of a word using multiple Cypher queries with a plain BFS algorithm.

      This is good for large sub-graph expand because it breaks huge memory consumption into sub-expand queries. But this endpoint sends multiple queries to database which incurs roundtrips and large Network I/O

      Parameters:
      word - The word to expand
      Returns:
      a JSON representation of the expanded sub-graph
    • expandApoc

      @GET @Path("/expandApoc/{word}") @Produces("application/json") public jakarta.ws.rs.core.Response expandApoc(@NotNull @PathParam("word") @NotNull String word, @NotNull @QueryParam("maxHops") @DefaultValue("-1") @NotNull String maxHops)
      Recursively find all related terms and definitions of a word using a single Cypher query with apoc extension.

      This is bad for large sub-graph expand because it will exhaust memories allocated for the query in database. This is good for small-subgraph expand when WS and database are far away from each other.

      Parameters:
      word - The word to expand
      maxHops - The max length of expanded path. Use "-1" for unlimitedly long path.
      Returns:
      a JSON representation of the expanded sub-graph. The format of the JSON would be