{"id":25968871,"url":"https://github.com/daniel-keogh/graph-theory","last_synced_at":"2026-05-30T18:31:17.521Z","repository":{"id":121011549,"uuid":"234400346","full_name":"daniel-keogh/graph-theory","owner":"daniel-keogh","description":"A Python program that uses an NFA to check if a regular expression matches a given string","archived":false,"fork":false,"pushed_at":"2020-05-18T22:16:03.000Z","size":486,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-04T22:37:15.519Z","etag":null,"topics":["graph-theory","nfa","python","python3","regex","regex-match","regular-expressions","thompson-algorithm"],"latest_commit_sha":null,"homepage":"https://daniel-keogh.github.io/graph-theory/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daniel-keogh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-16T19:57:11.000Z","updated_at":"2021-06-21T14:24:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"f1e14803-1ee4-4e53-b729-f8b59a98f4b8","html_url":"https://github.com/daniel-keogh/graph-theory","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/daniel-keogh/graph-theory","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-keogh%2Fgraph-theory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-keogh%2Fgraph-theory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-keogh%2Fgraph-theory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-keogh%2Fgraph-theory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daniel-keogh","download_url":"https://codeload.github.com/daniel-keogh/graph-theory/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-keogh%2Fgraph-theory/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33705207,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-30T02:00:06.278Z","response_time":92,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graph-theory","nfa","python","python3","regex","regex-match","regular-expressions","thompson-algorithm"],"created_at":"2025-03-04T22:35:24.731Z","updated_at":"2026-05-30T18:31:17.513Z","avatar_url":"https://github.com/daniel-keogh.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Graph Theory\n\nY3S2 Graph Theory Project\n\n## Description\n\nA Python program that can build a non-deterministic finite automaton (NFA) from a regular expression, and\ncan use the NFA to check if the regular expression matches a given string of text.\n\nThe program uses an algorithm known as [Thompson's construction](https://en.wikipedia.org/wiki/Thompson%27s_construction),\na method of transforming a regular expression into an equivalent NFA. The code works by composing small NFA fragments\nthat represent part of the regular expression, and then proceeding to build larger NFAs from those smaller NFA fragments.\nIf the given string is accepted by the NFA, the program will output `True`, and\n`False` otherwise.\n\n### Operators\n\nThe below operators/metacharacters are implemented:\n\n| Operator | Represents | NFA Fragment \\* |\n| :------: | :--------- | :-----------: |\n| `.` | Concatenation. | ![concat] |\n| `\\|` | Alternation/Union. | ![union] |\n| `?` | Zero-or-one occurrences of a character. | ![optional] |\n| `+` | One-or-more occurrences of a character. | ![plus] |\n| `*` | Zero-or-more occurrences of a character. | ![kleene] |\n\n\\* NFA fragment diagrams taken from [these slides](https://github.com/ianmcloughlin/slides-thompson/blob/master/slides.pdf)\non Thompson's Construction.\n\n## Running\n\nThe program can be run as follows, using the `-m` argument in order to execute the `__main__.py` module.\n\n```sh\n$ python3 -m match -r REGEX -t TEXT\n```\n\n### Command-Line Arguments\n\n| Argument | Description |\n| -------- | ---------- |\n| `-h/--help` | Prints a help message and then exits. |\n| `-v/--version` | Shows the program's version number then and exits. |\n| `-r/--regex` | The regular expression to match. |\n| `-t/--text` | The string of text you want to try and match against the pattern defined by the regular expression. |\n\n#### Example\n\n![Running Example][run]\n\n## Installing with pip\n\nFrom inside the root of the repository, run:\n\n```sh\n$ sudo pip3 install .\n```\n\nThis will allow you to run the program system-wide, while omitting the `python3 -m`.\n\n![PIP Example][pip]\n\n**_Note:_** You may first need to `apt install python3-pip` before installing.\n\n### Removing\n\nYou can uninstall it again by running `sudo pip3 uninstall match`.\n\n## Testing\n\nTests are located in the `tests/` directory.\n\n### Run All Tests\n\n```sh\n$ python3 -m unittest discover --verbose\n```\n\n![\"Testing Example\"][tests]\n\n### Run a Single Test\n\n```sh\n$ python3 tests/[file_name].py\n```\n\n## Documentation\n\nThe documentation for this project is deployed on [GitHub Pages](https://daniel-keogh.github.io/graph-theory/).\n\n### Building the Docs\n\n**_Note:_** You may first need to install the [Sphinx](https://www.sphinx-doc.org/en/master/) documentation generator.\nOn Debian-based Linux distributions this can be done by running:\n\n```sh\n$ sudo apt install python3-sphinx\n```\n\nYou should then be able to run `make html` from within the `docs/` directory to reproduce the HTML files, which will be\nplaced in the `_build/html` directory.\n\n![\"Sphinx Example\"][docs]\n\n### Notes\n\n- The docstrings thoughout this project follow the reStructuredText (reST) format outlined in [PEP 287](https://www.python.org/dev/peps/pep-0287/).\n\n- The contents of the `docs/` directory were mostly auto-generated using the `sphinx-quickstart` command,\nfollowed by `sphinx-apidoc -o . ../match --separate` to create the RST files.\n\n\u003c!-- Console Images --\u003e\n[run]: https://user-images.githubusercontent.com/37158241/76702521-5a20a980-66c2-11ea-8813-589fd489a5e3.PNG \"Running the Program\"\n\n[pip]: https://user-images.githubusercontent.com/37158241/80708607-e1e03d00-8ae3-11ea-95cb-239ddf52259c.PNG \"PIP Install\"\n\n[tests]: https://user-images.githubusercontent.com/37158241/82117563-b3f82b00-9768-11ea-8a72-61f49be8d8fc.PNG \"Testing\"\n\n[docs]: https://user-images.githubusercontent.com/37158241/76702668-75d87f80-66c3-11ea-9db0-50f4fc75f2b8.PNG \"Sphinx Build\"\n\n\u003c!-- NFA Images --\u003e\n[union]: https://user-images.githubusercontent.com/37158241/76761641-b13c8200-6787-11ea-8821-7d3c31744855.png \"Union\"\n\n[kleene]: https://user-images.githubusercontent.com/37158241/76747391-f6a18500-6770-11ea-8104-1d70db17d268.png \"Kleene Star\"\n\n[concat]: https://user-images.githubusercontent.com/37158241/76760396-7e918a00-6785-11ea-80cf-ea910d507358.png \"Concatenation\"\n\n[optional]: https://user-images.githubusercontent.com/37158241/76747393-f7d2b200-6770-11ea-9f3b-eed4eb2fbf1a.png \"Optional\"\n\n[plus]: https://user-images.githubusercontent.com/37158241/76747394-f7d2b200-6770-11ea-8891-2632ec9ccec5.png \"Plus Operator\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel-keogh%2Fgraph-theory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaniel-keogh%2Fgraph-theory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel-keogh%2Fgraph-theory/lists"}