#url /skg-if-orkg/v1
#type api
#base https://w3id.org/skg-if/sandbox/orkg
#title SKG-IF API for ORKG
#description SKG-IF compliant API exposing ORKG (Open Research Knowledge Graph) bibliographic data as JSON-LD, following the <a href="https://skg-if.github.io/interoperability-framework/" target="_blank">Scholarly Knowledge Graph Interoperability Framework specification</a>.
#html_meta_description SKG-IF API for ORKG: access bibliographic metadata via the Scholarly Knowledge Graph Interoperability Framework.
#version 0.1.0
#contacts <a href="mailto:info@orkg.org" target="_blank">info@orkg.org</a>
#license This document is licensed with a <a href="https://creativecommons.org/licenses/by/4.0/legalcode" target="_blank">Creative Commons Attribution 4.0 International License</a>, while the REST API itself has been created using <a href="https://github.com/opencitations/ramose" target="_blank">RAMOSE, the Restful API Manager Over SPARQL Endpoints</a>, which is licensed with an <a href="https://opensource.org/licenses/ISC" target="_blank">ISC license</a>.
#endpoint https://orkg.org/triplestore
#method post
#addon ramose.skg_if
#disable_params require,filter,sort,format,json

#url /products/{local_identifier}
#type operation
#local_identifier str(http://orkg\.org/orkg/resource/R\d+)
#method get
#description Returns a single research product from ORKG identified by its resource URI.
#call /products/http://orkg.org/orkg/resource/R1637585
#output_json {
    "@context": [
        "https://w3id.org/skg-if/context/1.1.0/skg-if.json",
        "https://w3id.org/skg-if/context/1.0.0/skg-if-api.json"
    ],
    "meta": {
        "local_identifier": "https://w3id.org/skg-if/sandbox/orkg/skg-if-orkg/v1/products/http://orkg.org/orkg/resource/R1637585?page=1&page_size=1",
        "entity_type": "search_result_page",
        "part_of": {
            "local_identifier": "https://w3id.org/skg-if/sandbox/orkg/skg-if-orkg/v1/products/http://orkg.org/orkg/resource/R1637585",
            "entity_type": "search_result",
            "total_items": 1,
            "first_page": {
                "local_identifier": "https://w3id.org/skg-if/sandbox/orkg/skg-if-orkg/v1/products/http://orkg.org/orkg/resource/R1637585?page=1&page_size=1",
                "entity_type": "search_result_page"
            },
            "last_page": {
                "local_identifier": "https://w3id.org/skg-if/sandbox/orkg/skg-if-orkg/v1/products/http://orkg.org/orkg/resource/R1637585?page=1&page_size=1",
                "entity_type": "search_result_page"
            }
        }
    },
    "@graph": [
        {
            "local_identifier": "http://orkg.org/orkg/resource/R1637585",
            "entity_type": "product",
            "product_type": "literature",
            "titles": {
                "none": [
                    "HERITRACE: A User-Friendly Semantic Data Editor with Change Tracking and Provenance Management for Cultural Heritage Institutions"
                ]
            },
            "identifiers": [
                {
                    "value": "10.6092/ISSN.2532-8816/21218",
                    "scheme": "doi"
                }
            ],
            "contributions": [
                {
                    "role": "author",
                    "by": {
                        "name": "Arcangelo Massari",
                        "entity_type": "agent",
                        "local_identifier": "http://orkg.org/orkg/resource/R1637559",
                        "identifiers": [
                            {
                                "value": "0000-0002-8420-0696",
                                "scheme": "orcid"
                            }
                        ]
                    },
                    "rank": 1
                },
                {
                    "role": "author",
                    "by": {
                        "name": "Silvio Peroni",
                        "entity_type": "agent",
                        "local_identifier": "http://orkg.org/orkg/resource/R9566",
                        "identifiers": [
                            {
                                "value": "0000-0003-0530-4305",
                                "scheme": "orcid"
                            }
                        ]
                    },
                    "rank": 2
                }
            ],
            "manifestations": [
                {
                    "dates": {
                        "publication": [
                            "2025-07-01T00:00:00"
                        ]
                    },
                    "biblio": {
                        "in": {
                            "name": "Umanistica Digitale",
                            "entity_type": "venue",
                            "local_identifier": "http://orkg.org/orkg/resource/R585576",
                            "identifiers": [
                                {
                                    "value": "2532-8816",
                                    "scheme": "issn"
                                }
                            ]
                        }
                    }
                }
            ],
            "topics": [
                {
                    "term": {
                        "local_identifier": "http://orkg.org/orkg/resource/R141823",
                        "entity_type": "topic",
                        "labels": {
                            "none": "Semantic Web"
                        }
                    }
                }
            ]
        }
    ]
}
#format skg_if,to_skg_if,application/ld+json
#default_format skg_if
#sparql PREFIX orkgc: <http://orkg.org/orkg/class/>
PREFIX orkgp: <http://orkg.org/orkg/predicate/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?local_identifier ?identifier_scheme ?identifier_value
       ?title ?title_lang ?product_type
       ?manifestation_dates_type ?manifestation_dates_value
       ?manifestation_biblio_in_name ?manifestation_biblio_in_local_identifier
       ?manifestation_biblio_in_identifier_scheme ?manifestation_biblio_in_identifier_value
WHERE {
  BIND(<[[local_identifier]]> AS ?local_identifier)
  ?local_identifier a ?_type_class .
  FILTER(STRSTARTS(STR(?_type_class), STR(orkgc:)))
  FILTER(?_type_class != orkgc:Resource)
  BIND(
    IF(?_type_class = orkgc:Paper, "literature",
    IF(?_type_class IN (orkgc:Dataset, orkgc:BENCHMARK_DATASET), "research data",
    "other"))
  AS ?product_type)
  OPTIONAL {
    ?local_identifier rdfs:label ?title_raw .
    BIND(STR(?title_raw) AS ?title)
    BIND(IF(LANG(?title_raw) != "", LANG(?title_raw), "") AS ?title_lang)
  }
  OPTIONAL {
    ?local_identifier orkgp:P29 ?year .
    OPTIONAL { ?local_identifier orkgp:P28 ?month_raw . }
    BIND(IF(BOUND(?month_raw), IF(xsd:integer(?month_raw) < 10, CONCAT(STR(?year), "-0", STR(?month_raw)), CONCAT(STR(?year), "-", STR(?month_raw))), STR(?year)) AS ?manifestation_dates_value)
    BIND("publication" AS ?manifestation_dates_type)
  }
  OPTIONAL {
    ?local_identifier orkgp:P26 ?doi_val .
    BIND("doi" AS ?identifier_scheme)
    BIND(?doi_val AS ?identifier_value)
  }
  OPTIONAL {
    ?local_identifier orkgp:HAS_VENUE ?venue_resource .
    ?venue_resource rdfs:label ?manifestation_biblio_in_name .
    BIND(STR(?venue_resource) AS ?manifestation_biblio_in_local_identifier)
    OPTIONAL {
      ?venue_resource orkgp:P74029 ?venue_issn .
      BIND("issn" AS ?manifestation_biblio_in_identifier_scheme)
      BIND(STR(?venue_issn) AS ?manifestation_biblio_in_identifier_value)
    }
  }
}

@@join ?local_identifier ?local_identifier type=left
PREFIX orkgp: <http://orkg.org/orkg/predicate/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?local_identifier ?contribution_by_name
       ?contribution_by_local_identifier ?contribution_role ?_contribution_key
       ?contribution_by_identifier_scheme ?contribution_by_identifier_value
WHERE {
  BIND(<[[local_identifier]]> AS ?local_identifier)
  ?local_identifier orkgp:hasAuthors ?authors .
  ?authors ?seq_pred ?author .
  FILTER(STRSTARTS(STR(?seq_pred), "http://www.w3.org/1999/02/22-rdf-syntax-ns#_"))
  BIND("author" AS ?contribution_role)
  ?author rdfs:label ?contribution_by_name .
  BIND(STR(?author) AS ?contribution_by_local_identifier)
  BIND(CONCAT(STR(?local_identifier), "/author/", STRAFTER(STR(?seq_pred), "http://www.w3.org/1999/02/22-rdf-syntax-ns#_")) AS ?_contribution_key)
  OPTIONAL {
    ?author orkgp:HAS_ORCID ?orcid .
    BIND("orcid" AS ?contribution_by_identifier_scheme)
    BIND(?orcid AS ?contribution_by_identifier_value)
  }
}
ORDER BY xsd:integer(STRAFTER(STR(?seq_pred), "http://www.w3.org/1999/02/22-rdf-syntax-ns#_"))

@@join ?local_identifier ?local_identifier type=left
PREFIX orkgp: <http://orkg.org/orkg/predicate/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?local_identifier ?topic_term ?topic_label ?topic_label_lang
WHERE {
  BIND(<[[local_identifier]]> AS ?local_identifier)
  ?local_identifier orkgp:P30 ?field .
  BIND(STR(?field) AS ?topic_term)
  ?field rdfs:label ?topic_label_raw .
  BIND(STR(?topic_label_raw) AS ?topic_label)
  BIND(IF(LANG(?topic_label_raw) != "", LANG(?topic_label_raw), "") AS ?topic_label_lang)
}
