diff --git "a/README.md" "b/README.md" --- "a/README.md" +++ "b/README.md" @@ -1,110 +1,1352 @@ --- -tags: - - knowledge-graph - - rdf - - n-triples - - sparql - - semantic-web - - stackoverflow - - question-answering -pretty_name: StackOverflow Knowledge Graph - C++ -license: cc-by-sa-4.0 -size_categories: - - 100M . +@prefix xsd: . + + + so:creationDate "2024-03-15T10:30:00Z"^^xsd:dateTime . ``` -- `README.md`: Hugging Face dataset card rendered from this template. -- `schema.nt`: shared ontology and schema triples. -- `c++/part*.nt`: C++ instance triples serialized as N-Triples. +These fields describe the source snapshot, not a complete revision history. +Last activity or last edit dates alone do not establish technical freshness. + +| Entity | Representation | +| --- | --- | +| Question | `so:Question`, identified by `http://stackoverflow.com/q/{post_id}` | +| Answer | `so:Answer`, identified by `http://stackoverflow.com/a/{post_id}` | +| Comment | `so:Comment`, with `so:QuestionComment` or `so:AnswerComment` for comments on discussions | +| Tag | `so:Tag`, identified by `http://stackoverflow.com/tags/{encoded_tag}` | +| Tag documentation | `so:TagWiki` and `so:TagExcerpt`, connected to their tag | + +Questions, answers and documentation posts carry source post IDs. Available +properties include titles, original HTML bodies, scores, aggregated upvote and +downvote counts, timestamps and content licenses. Comments carry text, scores, +creation dates and licenses. Question-specific properties include source answer, +view and favorite counts. Missing source values are omitted. Individual voters +and user-profile entities are not represented by this mapping. + +| Relationship | Meaning | Exported inverse | +| --- | --- | --- | +| `so:hasAnswer` | Question to one of its answers | `so:answersQuestion` | +| `so:acceptedAnswer` | Question to its resolved accepted answer | `so:acceptedAnswerOf` | +| `so:hasComment` | Post to a comment on it | `so:commentOn` | +| `so:taggedWith` | Question to one of its source tags | `so:tagsQuestion` | +| `so:hasTagWiki` | Tag to its documentation post | `so:tagWikiOf` | +| `so:hasTagExcerpt` | Tag to its short description | `so:tagExcerptOf` | +| `so:linkedTo` | Directed source PostLinks relation of type 1 | None | +| `so:duplicateOf` | Directed source PostLinks relation of type 3 | None | + +The listed inverse relationships are written as triples, so querying them does +not require an inference engine. A link or duplicate edge does not imply a reverse +edge. The mapper also writes applicable superclass types. Answer status uses +classes such as `so:AnsweredQuestion`, `so:UnansweredQuestion` and +`so:QuestionWithAcceptedAnswer`; missing edges alone do not establish unanswered +status. An accepted answer or a high score does not establish technical correctness. +The ontology defines `so:possibleBetterAnswer`, but this exporter does not generate +that assessment. + +## How the language graphs connect + +Language membership is determined from question tags using the release's selection +registry. Matching covers configured base tags, version patterns and aliases. +Answers and discussion comments inherit their question's graph membership; their +bodies are not classified independently. Questions without a registry match are +routed to the `http://stackoverflow.com/extra-languages` graph in the full export. +This category is not an additional match for questions already assigned to a +registered language. + +### The additional extra-languages dataset + +`extra-languages` can be published as its own dataset alongside the 39 language +datasets. Its graph IRI is `http://stackoverflow.com/extra-languages`. It contains +questions with no match in the release's configured language registry, including +their answers, comments and outgoing question links. This can include questions +about unconfigured languages and questions without a recognized language tag; +it is not a classification into one additional programming language. + +The graph also holds tags without recorded graph usage and tag documentation +without a resolved owner. Its publication package includes its discussion shards, +the schema and all shared documentation shards. Regular language packages include +shared documentation from this graph, but not its complete discussion collection. +Load the extra-languages dataset from the same export identity to resolve links +whose target discussions are in that graph. It complements the configured +language selections without assigning those discussions to another language. + +There are three ways language graphs share or connect content: + +1. **The same discussion in several graphs.** If a question matches both Python + and Java, its question, answer and comment statements are emitted into both + language graphs with the same entity IRIs. This overlap follows source tags; + it is not a translation or an inferred similarity relationship. +2. **Shared tags and documentation.** Tags retain their identities across graphs. + Their definitions, wikis, excerpts and documentation comments are routed to + the graphs of questions using those tags. Tags without recorded usage, and + documentation without a resolved tag owner, go to `extra-languages`. +3. **Links between different questions.** `so:linkedTo` and `so:duplicateOf` point + from a question to another question's IRI. The edge is stored in the source + question's language graphs. Its target can belong to another language graph. +For example, Q1 has tags matching both Python and Java, so its discussion is +represented in both graphs. Q2 belongs to Java and is the target of a source link +from Q1. The following statements illustrate this arrangement: -## Data Model And Coverage +| Named graph | Subject | Predicate | Object | +| --- | --- | --- | --- | +| `http://stackoverflow.com/python` | Q1 | `so:linkedTo` | Q2 | +| `http://stackoverflow.com/java` | Q1 | `so:linkedTo` | Q2 | +| `http://stackoverflow.com/java` | Q2 | `rdf:type` | `so:Question` | -The graph links Stack Overflow entities and relations, including questions, answers, comments, tags, vote aggregates, and question-to-question links. +Q1 stands for `http://stackoverflow.com/q/1` in both graphs; Q2 stands for +`http://stackoverflow.com/q/2`. The two Q1 entries describe the same entity. +There is no additional "same entity" edge. The two `so:linkedTo` statements are +copies of the same source link stored in different named graphs. -Coverage scope: +These IDs are illustrative. Q2's reference in the Python graph +does not by itself include Q2's title, body or answers there. Those descriptions +are available when the package containing Q2's discussion has been loaded. -- records are retained when they match the Stack2Graph supported language-tag set -- this repository contains only the C++ shard -- a question may appear in more than one language repository when it has multiple programming-language tags +Each language package contains the selected language's discussion shards plus +all shared tag-documentation shards and the schema. A Java graph appearing in a +Python package's inventory can therefore contain shared documentation without +containing Java's full question-and-answer collection. The same applies to +`extra-languages`: its shared documentation can be present without its discussion +shards. A referenced question can have no local description when its discussion +is only in another package. -## Recommended Use +To follow these connections across languages, load the relevant packages from +the same export identity into one RDF dataset and preserve the named graphs. +Shared shards occur in multiple packages; avoid importing them repeatedly into +stores that retain duplicate statements. For entity counts across graphs, use +`COUNT(DISTINCT ?question)`. Summing quad counts measures graph statements, +including repeated statements in different language graphs, rather than unique +discussions. -Use this dataset for graph retrieval, SPARQL diagnostics, RAG experiments, and knowledge graph research for programming topics. It is not intended as row-wise tabular training input. +`publication.json` records each file's path, stored byte count, SHA-256 checksum +and graph key, together with the export identity. RDF files are under `graphs/`. +Internal run manifests, QLever indexes, credentials and uploader source are +excluded from the archive. -Load `schema.nt` and the files under `c++/` into an RDF-capable store. Map language triples to named graph: +## Loading and querying -```text -http://stackoverflow.com/c++ +Load the `.nq` files as N-Quads and preserve their embedded named graph IRIs. +For `.nq.gz` files, decompress them first if your RDF store cannot read gzip. + +The following query counts loaded quads by graph. Use the graph inventory above +to check the result, or restrict queries to `http://stackoverflow.com/c%2B%2B` when working +with the selected language. + +```sparql +SELECT ?graph (COUNT(*) AS ?quads) +WHERE { GRAPH ?graph { ?s ?p ?o } } +GROUP BY ?graph ``` -Example language-scoped query: +Retrieve questions and their available answers in this language graph: ```sparql -SELECT ?s ?p ?o +PREFIX so: + +SELECT ?question ?title ?answer WHERE { - GRAPH { - ?s ?p ?o + GRAPH { + ?question a so:Question . + OPTIONAL { ?question so:hasTitle ?title } + OPTIONAL { ?question so:hasAnswer ?answer } } } -LIMIT 100 +LIMIT 25 ``` -## Restore With Stack2Graph +After loading other language packages, find linked or duplicate questions whose +descriptions are available in another named graph: -You do not need to rebuild triples from XML to use this dataset. +```sparql +PREFIX so: -Typical workflow: +SELECT DISTINCT ?question ?relation ?target ?targetGraph ?targetTitle +WHERE { + GRAPH { + VALUES ?relation { so:linkedTo so:duplicateOf } + ?question a so:Question ; ?relation ?target . + } + GRAPH ?targetGraph { + ?target a so:Question ; so:hasTitle ?targetTitle . + } + FILTER (?targetGraph != ) +} +LIMIT 25 +``` -1. Clone Stack2Graph and configure `.env` with service paths and an HF token. -2. Start local services: +The second query returns only targets with loaded descriptions and titles. A +target can occur in several graphs through overlapping tag selections; this +does not mean the source and target questions use different languages exclusively. -```bash -docker compose up -d -``` +## Uses and limitations -3. Download and prepare the knowledge graph service state: +The graph supports SPARQL analysis and retrieval over Stack Overflow discussions, +including retrieval-augmented question answering. It represents the source +snapshot; later edits and deletions on Stack Overflow are not reflected here. -```bash -python -m experiment.sources.hf -``` +## Quality notes -## Quality Notes +- Votes are represented as aggregated upvote and downvote counts. Individual + vote events and voter identities are not included. +- The graph includes selected moderation-related fields, such as a question's + closure date, but does not represent the full moderation context or revision + history. +- Community-generated Stack Overflow content can contain errors, outdated + information and bias. Changes in languages, libraries and development practices + can make advice less applicable over time. +- Scores, accepted-answer status and recent activity are source signals; they + do not establish that an answer is correct or current. -- Vote information is represented as aggregates, not raw individual vote events. -- Not all moderation context or full revision history is represented. -- Community-generated Stack Overflow content may contain errors, outdated information, bias, or temporal drift. +## License and attribution -## License And Attribution +This dataset is derived from Stack Overflow content. Its declared dataset license +is [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/) +(`CC-BY-SA-4.0`). Preserve required attribution and license notices when +redistributing derived artifacts, and identify changes where required. -This dataset is derived from Stack Overflow content and is distributed under `CC-BY-SA-4.0`. -Preserve required attribution and license notices when redistributing derived artifacts. +Individual source contributions retain their applicable license terms. +[Stack Overflow's licensing guidance](https://stackoverflow.com/help/licensing) +distinguishes CC BY-SA 2.5, 3.0 and 4.0 according to contribution date. A dataset-level +license declaration does not replace those source notices. The graph preserves +source-provided license labels in `so:contentLicense` where available. Consult the +original posts and revision records for author attribution and applicable terms. +The Hugging Face metadata declares `cc-by-sa-4.0`, consistent with the MDC +publication. For dataset questions, use this repository's Community discussion +page; source-post attribution and licensing remain attached to the original content. ## Citation -If you use this dataset, cite the Stack2Graph project and preserve Stack Overflow attribution requirements: +If you use this dataset, cite the Stack2Graph project. The research citation +accompanies the required attribution for the underlying Stack Overflow content. + +Kleybolte, L. A., Ventura, V., & Zarcone, A. (2026). *Stack2Graph: A Structured +Knowledge Representation of Stack Overflow Data for Retrieval-based Question +Answering*. In *Proceedings of the Knowledge Graphs and Large Language Models +Workshop (KG-LLM) @ LREC26* (pp. 120-133). European Language Resources Association +(ELRA). [https://doi.org/10.63317/583q4d3mwbdu](https://doi.org/10.63317/583q4d3mwbdu). + +## Export provenance + +These fingerprints identify the inputs and exporter used for this release. +The export identity describes the build configuration and inputs; file checksums +are listed separately in `publication.json`. + +| Component | Fingerprint | +| --- | --- | +| Export identity | `4d415cea2977835bf886c177f2bfc309a22738e145591f9c7ae4256e9bd086d5` | +| Source snapshot identity | `56fe643952cec74b17ea13d91edc8ad95181326156177c94cce48d3fed9834b9` | +| Language registry | `d2a7357c04e7f47d9bb598189aeeb7db0680d6b35f0d9695d8d2e544121afb8e` | +| Ontology | `1fc4dc1cc73a1baeddc0e1d70dc22ab95962581c6b61eb895ddcc70956621153` | +| Exporter | `8d9b9bac86b5e9c19bb0ce5af022e8a1ecd14c9f8e82e73169cbdb8455470422` | -- Kleybolte, L. A., Ventura, V., & Zarcone, A. (2026). Stack2Graph: A Structured Knowledge Representation of Stack Overflow Data for Retrieval-based Question Answering . In Proceedings of the Knowledge Graphs and Large Language Models Workshop (KG-LLM) @ LREC26 (pp. 120-133). European Language Resources Association (ELRA). https://doi.org/10.63317/583q4d3mwbdu. +Source code and documentation: [stack2graph](https://github.com/tha-atlas/Stack2Graph).