@prefix this: . @prefix sub: . @prefix np: . @prefix grlc: . @prefix dct: . @prefix nt: . @prefix npx: . @prefix xsd: . @prefix rdfs: . @prefix orcid: . @prefix prov: . @prefix foaf: . sub:Head { this: a np:Nanopublication; np:hasAssertion sub:assertion; np:hasProvenance sub:provenance; np:hasPublicationInfo sub:pubinfo . } sub:assertion { sub:get-thread-of-contribution a grlc:grlc-query; dct:description "Returns the whole discussion thread that the given contribution belongs to: its first contribution and all responses at any depth, whichever contribution of the thread is given. A contribution is a schema:Statement or schema:Question with its text in rdf:value, following the Nanoarguments model. It responds to another contribution through as:inReplyTo or a rhetorical CiTO stance (supports, disputes, qualifies, agreesWith, and so on) or na:tests, pointing at the contribution itself or at the nanopublication holding it; citation relations such as cito:citesAsEvidence do not make it a response. One row per contribution, in the columns a thread view reads (reply, relation, in_reply_to, by, date). The relation is the CiTO stance where there is one, else asks for a question, answers for a statement responding to a question, and replies otherwise. A contribution republished under the same IRI shows its latest version by its author: one signed with the key of the nanopublication that minted the IRI, where that nanopublication holds the contribution itself. A nanopublication by anyone else that keeps the IRI, such as an override, is not taken as a new version of it. Retracted and superseded nanopublications and example nanopublications are left out."; dct:license ; rdfs:label "Get the discussion thread of a contribution"; grlc:endpoint ; grlc:sparql """prefix rdf: prefix dct: prefix np: prefix npa: prefix npx: prefix prov: prefix foaf: prefix schema: prefix schemah: prefix as: prefix cito: prefix na: select ?reply ?reply_label ?relation ?in_reply_to ?by ?by_label ?date ?support_stance ?dispute_stance ?np ?np_label where { { select ?reply ?np ?a ?prov ?pi ?date (max(if(?ctype = schema:Question, 1, 0)) as ?isQuestion) (min(str(?p)) as ?parentStr) (min(if(?rel = as:inReplyTo, \"~\", str(?rel))) as ?stanceStr) (max(if(bound(?pqa), 1, 0)) as ?toQuestion) where { { # the latest valid, non-example version of each contribution select ?reply ?onp (max(?created) as ?date) where { { # the contributions of the thread that the given contribution belongs to select distinct ?reply where { { select distinct ?root where { values ?atype { schema:Statement schema:Question } graph ?aa { ?_resource_iri a ?atype ; rdf:value ?av . } graph npa:graph { ?anp np:hasAssertion ?aa ; npa:hasValidSignatureForPublicKeyHash ?apk . filter not exists { ?ax npx:invalidates ?anp ; npa:hasValidSignatureForPublicKeyHash ?apk . } } ?_resource_iri (as:inReplyTo|na:tests|cito:agreesWith|cito:confirms|cito:corrects|cito:critiques|cito:derides|cito:disagreesWith|cito:discusses|cito:disputes|cito:extends|cito:parodies|cito:qualifies|cito:refutes|cito:repliesTo|cito:retracts|cito:reviews|cito:ridicules|cito:speculatesOn|cito:supports|cito:updates|npx:introduces)* ?root . filter not exists { values ?rrel { as:inReplyTo na:tests cito:agreesWith cito:confirms cito:corrects cito:critiques cito:derides cito:disagreesWith cito:discusses cito:disputes cito:extends cito:parodies cito:qualifies cito:refutes cito:repliesTo cito:retracts cito:reviews cito:ridicules cito:speculatesOn cito:supports cito:updates } graph ?ra { ?root ?rrel ?rt . } values ?rtt { schema:Statement schema:Question } graph ?rta { ?rt a ?rtt ; rdf:value ?rtv . } filter(?rt != ?root) } } } ?reply (as:inReplyTo|na:tests|cito:agreesWith|cito:confirms|cito:corrects|cito:critiques|cito:derides|cito:disagreesWith|cito:discusses|cito:disputes|cito:extends|cito:parodies|cito:qualifies|cito:refutes|cito:repliesTo|cito:retracts|cito:reviews|cito:ridicules|cito:speculatesOn|cito:supports|cito:updates|npx:introduces)* ?root . } } values ?type { schema:Statement schema:Question } graph ?va { ?reply a ?type ; rdf:value ?vv . } graph npa:graph { ?vnp np:hasAssertion ?va ; np:hasPublicationInfo ?vpi ; npa:hasValidSignatureForPublicKeyHash ?vpk ; dct:created ?created . filter not exists { ?vx npx:invalidates ?vnp ; npa:hasValidSignatureForPublicKeyHash ?vpk . } } filter not exists { graph ?vpi { ?vnp npx:hasNanopubType npx:ExampleNanopub . } } # only its author's versions count: those signed with the key of the nanopublication # whose namespace the contribution's IRI was minted in, if that nanopublication holds # the contribution itself. Someone else's nanopublication keeping the IRI (an # override) is not a new version of it. Where the minting nanopublication does not # hold the contribution (an IRI taken over from a template, say), any version counts. bind(iri(replace(str(?reply), \"^(.*RA[A-Za-z0-9_-]{43}).*$\", \"$1\")) as ?onp) filter not exists { graph npa:graph { ?onp np:hasAssertion ?oa ; npa:hasValidSignatureForPublicKeyHash ?opk . } filter(?opk != ?vpk) graph ?oa { ?reply a ?otype ; rdf:value ?ov . } filter(?otype in (schema:Statement, schema:Question)) } } group by ?reply ?onp } graph npa:graph { ?np dct:created ?date ; np:hasAssertion ?a ; np:hasProvenance ?prov ; np:hasPublicationInfo ?pi ; npa:hasValidSignatureForPublicKeyHash ?npk . } values ?ctype { schema:Statement schema:Question } graph ?a { ?reply a ?ctype ; rdf:value ?cv . } # the same rule for the version of that date, which someone else's could share filter not exists { graph npa:graph { ?onp np:hasAssertion ?oa ; npa:hasValidSignatureForPublicKeyHash ?opk . } filter(?opk != ?npk) graph ?oa { ?reply a ?otype ; rdf:value ?ov . } filter(?otype in (schema:Statement, schema:Question)) } # what it responds to: a reply or a CiTO stance toward another contribution # (directly, or via the nanopublication that holds it) optional { values ?rel { as:inReplyTo na:tests cito:agreesWith cito:confirms cito:corrects cito:critiques cito:derides cito:disagreesWith cito:discusses cito:disputes cito:extends cito:parodies cito:qualifies cito:refutes cito:repliesTo cito:retracts cito:reviews cito:ridicules cito:speculatesOn cito:supports cito:updates } graph ?a { ?reply ?rel ?t . } optional { graph npa:graph { ?t np:hasAssertion ?ta . } graph ?ta { ?tn a ?tnt . } filter(?tnt in (schema:Statement, schema:Question)) } bind(coalesce(?tn, ?t) as ?p) filter(?p != ?reply) filter exists { values ?ptype { schema:Statement schema:Question } graph ?pa { ?p a ?ptype ; rdf:value ?pv . } graph npa:graph { ?pnp np:hasAssertion ?pa ; npa:hasValidSignatureForPublicKeyHash ?ppk . filter not exists { ?px npx:invalidates ?pnp ; npa:hasValidSignatureForPublicKeyHash ?ppk . } } } optional { graph ?pqa { ?p a schema:Question . } } } } group by ?reply ?np ?a ?prov ?pi ?date } bind(iri(?parentStr) as ?in_reply_to) bind(if(coalesce(?stanceStr, \"~\") != \"~\", ?stanceStr, if(?isQuestion = 1, \"asks\", if(!bound(?in_reply_to), \"\", if(?toQuestion = 1, \"answers\", \"replies\")))) as ?relation) optional { graph ?a { ?reply rdf:value ?reply_label . } } optional { graph ?prov { ?a prov:wasAttributedTo ?attr . } } optional { graph ?pi { ?np dct:creator ?creator . } } bind(coalesce(?attr, ?creator) as ?by) optional { graph ?pi { ?by foaf:name ?by_label . } } bind(cito:supports as ?support_stance) bind(cito:disputes as ?dispute_stance) bind(\"^\" as ?np_label) } order by ?date """ . } sub:provenance { sub:assertion prov:wasAttributedTo orcid:0000-0002-1267-0234 . } sub:pubinfo { orcid:0000-0002-1267-0234 foaf:name "Tobias Kuhn" . this: dct:created "2026-11-23T14:14:46.022+01:00"^^xsd:dateTime; dct:creator orcid:0000-0002-1267-0234; dct:license ; npx:embeds sub:get-thread-of-contribution; npx:supersedes ; rdfs:label "Get the discussion thread of a contribution"; nt:wasCreatedFromProvenanceTemplate ; nt:wasCreatedFromPubinfoTemplate , , ; nt:wasCreatedFromTemplate . sub:sig npx:hasAlgorithm "RSA"; npx:hasPublicKey "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCwUtewGCpT5vIfXYE1bmf/Uqu1ojqnWdYxv+ySO80ul8Gu7m8KoyPAwuvaPj0lvPtHrg000qMmkxzKhYknEjq8v7EerxZNYp5B3/3+5ZpuWOYAs78UnQVjbHSmDdmryr4D4VvvNIiUmd0yxci47dTFUj4DvfHnGd6hVe5+goqdcwIDAQAB"; npx:hasSignature "eMY8uSeIKURhD/fCmhVe/IV5cyf5pczIjr/mOcPADKBslPOWscbVevVFd8CImoXOiTlqy3Ac/EDZ/ivfID5fytth+OTto1F/7R8DNpnW68m1GcQ0RN8tWSkN6YeJ4jDESEO7/uveKSupEnlke13ZYaGxJIhvuz6NYMwANX8chvY="; npx:hasSignatureTarget this:; npx:signedBy orcid:0000-0002-1267-0234 . }