Skip to content

psygo/go_pattern_search

Repository files navigation

Go Pattern Search

In this project, we replicate the SGF game trees as graphs inside Neo4j, and then outsource the search through patterns to Neo4j, as it is an optimized graph database.

This project is heavily influenced and inspired by Waltheri's Go Pattern Search. In that project, its author used each game's last snapshot as a way of making comparisons with other games.

Another alternative to modeling this problem is through Regular Expressions — regexes can actually be modeled as graphs as well —, I believe. Since SGF files track move coordinates as strings, we could search patterns in strings as patterns in the game. Coincidentally, regular expressions are also used fact optimizations in my graph approach.

1. Tasks and Ideas

1.1. Tasks

(Kind lost my patience with implementing a Goban, so the current one is kind of crap, sorry. Everything seemed to be working fine but then I added some sizing parameters and things went awry.)

  • Pattern-Search
    • Sequential Pattern-Search
    • Stone-based filtering
      • Contains only selected stones
      • Contains selected stones
    • Rotation on Searches
    • Regular-search, such as player name, date, etc.
    • Add text/move-comment search.
    • Quadrant-based pattern search (reflections also count)
    • Region-based pattern search (reflections also count)
  • DB
    • SGF fields for the game nodes
    • Indexes
      • Index on moves
      • Index on edited stones
    • Data
      • Add large number of games (GoGod? Go4Go?)
      • Add tsumegos
      • Add lecture-based content (à la Yunguseng Dojang (Inseong Hwang))
  • UI
    • Goban Component
      • Stone placement
      • Stone deletion
      • Move numbering
      • Game Rules
        • Capture
        • Suicide
        • Ko
    • Filters
      • Sequential
      • Stone-based (for edited stones)
      • Region-based
      • Stone-based filtering
        • Contains only selected stones
        • Contains selected stones
    • URL-based filtering for the search
    • Regular-search, such as player name, date, etc.
    • Add text/move-comment search.

1.2. Ideas

  • Test it with GoGoD Games
    • Seems to work fine with it, it takes a couple of seconds once you get to 1,000s of games, but I think that might be fixed with some caching.
  • Include Yunguseng Dojang's files so we can index their large library.
    • There's something weird about this. There's something strange about the parsing of his files, such that they get bloated and overflow Neo4j's memory???
      • The same thing is happening for adding the tsumego collection.
  • Webscrape 101 Weiqi for its tsumegos.

2. Dev Setup

  1. Open Neo4j Desktop, and create a new project.
  2. Launch the Neo4j server.
  3. Create a new user with admin privileges, which will be used in the environment variables.
  4. Update the environment variables accordingly.
  5. Launch the NextJS project.

2.1. Tech Stack

  • Neo4j (Graph DBMS)
  • NextJS (ReactJS) + MUI
  • Sabaki's SGF Parser
  • Custom Go Board HTML Canvas Component

2.2. Environment Variables

2.2.1. .env

NEXTJS_PORT=

2.2.1. .env.local

PORT=

NEO4J_PORT=
NEO4J_USER=
NEO4J_PASSWORD=

3. References

3.1. Pattern Search

3.2 Board Editor

3.3. SGF

3.4. Related Questions on Stack Overflow

3.5. Miscellanea