Wednesday, September 18, 2013

SKOS Ontology with sample SPARQL

SKOS Simple Knowledge Organization System 

Select the first 3 concepts that have a skos:altLabel
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?concept  ?label
WHERE { ?concept skos:altLabel ?label . } LIMIT 3
Select the first 3 concepts that have a skos:altLabel, as RDF
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
CONSTRUCT   { ?concept skos:altLabel ?label  }
WHERE { ?concept skos:altLabel ?label . } LIMIT 3
Construct an RDF graph of terms with narrower terms but no broader terms, including a narrower terms plus the LCC number. Negation is in a state of flux (see http://www.w3.org/2009/sparql/wiki/Feature:Negation).
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX terms: <http://purl.org/dc/terms/>
CONSTRUCT   { 
    ?concept skos:narrower ?child .
    ?concept terms:LCC ?lcc.
}  WHERE { 
    ?concept skos:narrower ?child . 
    ?concept terms:LCC ?lcc.
    OPTIONAL { ?concept skos:broader ?parent }
    FILTER (!bound(?parent))
} LIMIT 3
Construct an RDF graph of terms with no broader terms in science:
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX terms: <http://purl.org/dc/terms/>
CONSTRUCT   { 
    ?concept terms:LCC ?lcc.
}  WHERE {  
    ?concept terms:LCC ?lcc.
    ?concept terms:created ?date
    OPTIONAL { ?concept skos:broader ?broader }
    FILTER (!bound(?broader))
    FILTER regex(?lcc, "^QA")
} LIMIT 50
Get all of the information about a concept. Check both ends of the relation, in case there are no inverseOf-def defined. In this case narrower is matched by broader, but that’s not the case for all RDF vocabularies. The many PREFIX clauses are here so that we get sane/readable prefixes in the output, but they’re unnecessary when generating RDF for machine consumption.
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX terms: <http://purl.org/dc/terms/>
CONSTRUCT   { 
    ?first ?relationOne <http://lcsubjects.org/subjects/sh2002000569#concept> .
    <http://lcsubjects.org/subjects/sh2002000569#concept> ?relationTwo ?second .
}  WHERE {  
    ?first ?relationOne <http://lcsubjects.org/subjects/sh2002000569#concept> .
   <http://lcsubjects.org/subjects/sh2002000569#concept> ?relationTwo ?second .   
} 
This example shows how a SPARQL endpoint might be used to get the data for AJAXy autocomplete functionality. In this example, the letters “Comp” have been typed. The str(…) is required to strip the language tags and the “i” indicates that case-insensitive matching should be done.
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT 
    ?label 
WHERE {  
   {  ?concept  skos:altLabel ?label . } UNION {  ?concept  skos:prefLabel ?label . }
   FILTER regex(str(?label), "^Comp", "i") .
} LIMIT 10

Related Posts:

  • Generate AI Images with ChatGPT Image created with ChatGPTYou must be for sure familiar with AI tools used for image generation, such as Midjourney, Leonardo AI, Photoshop, and so on. You must also be for sure familiar with ChatGPT, which, unlike the … Read More
  • Using AI to Make Money in 2023 1. Children’s Book AuthorUtilize ChatGPT to script your tale, and subsequently employ MidJourney or Stable Diffusion to construct illustrations for each page. Afterward, dispense your literary composition via Amazon’… Read More
  • How Flutter and ChatGPT Will Change App Development Steps for Creating a Chat-GPT Powered Flutter ApplicationHere’s an example of a working Flutter application built using ChatGPT and Flutter.Task: Building a Tic-Tac-Toe Game Application with FlutterPrompt: Create a tic-… Read More
  • 10 Best FlutterFlow App Templates in 2023The world of Flutter app development is ever-evolving, offering a plethora of templates that make the job of developers easier and more efficient. Whether you’re an aspiring Flutter developer or an experienced one, these … Read More
  • Top 8 Algorithms Every Programmer Should Know In programming, an algorithm is a set of instructions or a procedure for solving a specific problem or achieving a specific task. Algorithms can be expressed in any programming language and can be as simple as a seq… Read More

0 comments:

Post a Comment