{"id":43510338,"url":"https://github.com/cefriel/competence-kg","last_synced_at":"2026-02-03T12:50:28.029Z","repository":{"id":205838345,"uuid":"666064194","full_name":"cefriel/competence-kg","owner":"cefriel","description":"A tutorial on Knowledge Graphs discussing how to model the employee competences within a company","archived":false,"fork":false,"pushed_at":"2025-07-03T09:38:34.000Z","size":588,"stargazers_count":10,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-09T23:47:42.523Z","etag":null,"topics":["competences","cypher","data-modeling","knowledge-graph","langchain","llm","sparql","sql","tutorial"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cefriel.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-07-13T16:14:34.000Z","updated_at":"2025-07-03T09:38:37.000Z","dependencies_parsed_at":"2025-07-03T10:37:26.884Z","dependency_job_id":null,"html_url":"https://github.com/cefriel/competence-kg","commit_stats":null,"previous_names":["cefriel/competence-kg"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cefriel/competence-kg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cefriel%2Fcompetence-kg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cefriel%2Fcompetence-kg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cefriel%2Fcompetence-kg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cefriel%2Fcompetence-kg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cefriel","download_url":"https://codeload.github.com/cefriel/competence-kg/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cefriel%2Fcompetence-kg/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29046488,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T10:09:22.136Z","status":"ssl_error","status_checked_at":"2026-02-03T10:09:16.814Z","response_time":96,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["competences","cypher","data-modeling","knowledge-graph","langchain","llm","sparql","sql","tutorial"],"created_at":"2026-02-03T12:50:26.649Z","updated_at":"2026-02-03T12:50:28.014Z","avatar_url":"https://github.com/cefriel.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# `competence-kg`: a tutorial on Knowledge Graphs\n\nThis repository contains the material for the \"Knowledge Graphs Course\" erogated by [Cefriel](https://cefriel.com/). An example scenario (`Competence Registry`) is considered to implement and discuss modelling and querying over relational databases, graph databases and triplestores. The main topics are:\n- **Relational Databases** using [Postgres](https://www.postgresql.org/) (CSV import and SQL queries)\n- **Graph Database** using [Neo4j](https://neo4j.com/) (Graph modelling, CSV import and Cypher queries)\n- **RDF Database** using [RDFLib](https://pypi.org/project/rdflib/) (KG construction from CSV file using [RML](https://rml.io/) via [morph-kgc](https://github.com/morph-kgc/morph-kgc), SPARQL queries)\n- [_Bonus_] **Natural language QA** using [LangChain](https://www.langchain.com/) (querying different databases using the OpenAI API)\n\nIf you are interested in the course associated with this repository get in contact or send an email to [info@cefriel.com](mailto:info@cefriel.com).\n\n## The `Competence Registry` scenario\n\nA company would like to keep a record of the digital competences possessed by each employee. Each employee is described by their first name, last name, and the department they belong to.\nEach competence defined by the [DigComp](https://joint-research-centre.ec.europa.eu/digcomp/digcomp-framework_en) framework is described through four main fields: identifier, dimension, name, and description.\nEach employee can be associated with one or more competences. For each competence association, the following information can be provided: competence level (from 1 to 5) and the person's interest in gaining/increasing the skill.\n\n## How to run the code\nThe repository defines a `docker-compose.yml` file to run all the databases and the Jupyter notebooks as containers via Docker. The containers can be run all at once or separately.\n\nThe notebooks can be executed running the `competence-kg-notebook` container with the command:\n```bash\ndocker-compose up --force-recreate competence-kg-notebook\n```\n\n## Data\nThe data are randomly generated via the script available in the `notebooks/competence-kg-generate.ipynb` notebook. A constant `seed` is currently defined to always generate the default data contained in the `data` folder.\n\nThe files `employees.csv`, `assignment.csv` and `competences.csv` contain the data. The `*-iri.csv` files are generated to support the discussion on the RDF graph.\n\n## Relational Database\nThe relational database is modelled according to the ER diagram defined in the `model` folder. The diagram can be edited using the `draw.io` webapp.\n\nAn `init.sql` file is defined to initialise a `Postgres` database from the CSV files in the `data` folder. The database can be executed using the command:\n```bash\ndocker-compose up --force-recreate competence-kg-postgres\n```\nNote that if the option `--volumes` is not used with the command `docker-compose down` the status of the database is automatically persisted by Docker.\n\nThe `competence-kg-postgres.ipynb` notebook contains the code to inspect and query the database using the `SQL` syntax.\n\n## Graph Database\nThe graph database is modelled according to the diagram defined in the `model` folder. The diagram can be edited using the [arrows.app](https://arrows.app/) webapp.\n\nThe `competence-kg-neo4j.ipynb` notebook contains the code to import the data and to inspect and query the database. A `Neo4j` database is instantiated using the CSV files in the `data` folder and according to the graph model defined. The `Cypher` language is used to query the database.\n\nThe database can be executed using the command:\n```bash\ndocker-compose up --force-recreate competence-kg-neo4j\n```\n\nThe status of the database is automatically persisted in the `neo4j` folder as defined in the `docker-compose.yml` file. The folder can be deleted to erase all the data in the database.\n\n## RDF Database\nThe graph database is modelled according to the ontology `ontology.ttl` defined in the `model` folder and available online at [https://knowledge.c-innovationhub.com/competence-kg/schema](https://knowledge.c-innovationhub.com/competence-kg/schema). The ontology reuses the `foaf` vocabulary and adds further classes and properties. The ontology can be visualised using the [WebVOWL](http://vowl.visualdataweb.org/webvowl.html) webapp. In the `model` folder the file `content-negotiation.sh` shows how different cURL requests return different representations of the ontology.\n\nThe `competence-kg-rdf.ipynb` notebook contains the code to construct the knowledge graph and to inspect and query the it. An in-memory database is instantiated using the [RDFLib](https://pypi.org/project/rdflib/) library and the CSV files in the `data` folder. In this case, the `*-iri.csv` files are considered instead of the `assignment.csv` and `competences.csv` files. Indeed, we leverage the SKOS vocabulary describing the DigComp framework (already [available online](http://publications.europa.eu/resource/dataset/digital-competence-framework)) to enrich the company's graph without having to instantiate from the CSV all the data about the competences. \n\nThe mappings from the CSV files to the ontology are defined using YARRRML, compiled to RML using the [yatter](https://github.com/oeg-upm/yatter) tool and executed using the [morph-kgc](https://github.com/morph-kgc/morph-kgc) processor. The mappings are available in `mappings` folder. The `SPARQL` language is used to query the database.\n\nThe generated RDF graphs are serialised in the Turtle format and saved in the `rdf` folder together with a dump of the DigComp SKOS vocabulary.\n\n## LangChain QA\nThe `competence-kg-langchain.ipynb` notebook provides the code to execute QA (i.e., natural language querying) over the three databases leveraging the `langchain` library and the OpenAI GPT models. The `SQLDatabaseChain`, `GraphCypherQAChain`, `GraphSPARQLQAChain` are used in the code.\n\nA `credentials.json` file should be provided in the main folder with a valid key for the OpenAI API.\n\n```\n{\n    \"OPENAI_API_KEY\": \"PUT_HERE_YOUR_KEY\"\n}\n```\n\n## Contributing\n\nBefore contributing, please read carefully, complete and sign our [Contributor Licence Agreement](https://github.com/cefriel/contributing/blob/main/contributor-license-agreement.pdf). \n\nWhen contributing to this repository, please first discuss the change you wish to make via issue or any other available method with the repository's owners.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcefriel%2Fcompetence-kg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcefriel%2Fcompetence-kg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcefriel%2Fcompetence-kg/lists"}