Tagging

Get all tags with label mylabel

SELECT ?tag 
WHERE {
  ?tag a nao:Tag .
  ?tag nao:prefLabel 'mylabel' .
}

Get all tags for a file

SELECT ?tags ?labels 
WHERE {
  ?f nie:isStoredAs ?as ;
     nao:hasTag ?tags .
  ?as nie:url 'file:///home/path/to/file.txt' .
  ?tags a nao:Tag ;
     nao:prefLabel ?labels .
} ORDER BY ASC(?labels)

Creating a new tag

INSERT { 
  _:tag a nao:Tag ;
        nao:prefLabel 'mylabel' .
} WHERE {
  OPTIONAL {
     ?tag a nao:Tag ;
          nao:prefLabel 'mylabel'
  } .
  FILTER (!bound(?tag)) 
} 

Adding a tag that already exists to urn:XXX:ZZZ

INSERT { 
  <urn:XXX:ZZZ> nao:hasTag ?id 
} 
WHERE {
  ?id nao:prefLabel 'mylabel' 
}

Adding a new tag to a file

INSERT {
  _:tag a nao:Tag ;
        nao:prefLabel 'mylabel' .
  ?unknown nao:hasTag _:tag  
} WHERE {
  ?unknown nie:isStoredAs ?as .
  ?as nie:url 'file:///home/path/file'
}

Adding an existing tag to a file

INSERT {
  ?unknown nao:hasTag ?id 
} WHERE {
  ?unknown nie:isStoredAs ?as .
  ?as nie:url 'file:///home/path/file' .
  ?id nao:prefLabel 'mylabel' 
}

Removing a tag regardless of associated URNs

DELETE { 
  ?tag a nao:Tag 
} 
WHERE {
  ?tag nao:prefLabel 'mylabel'
}

Removing a tag for a URN

DELETE { 
  ?f nao:hasTag ?t 
} 
WHERE { 
  ?f nao:hasTag <urn:for:tag> 
}

A few complete examples

For files:

tracker-sparql -u -q "INSERT { 
   <file:///home/path/file> a nfo:Document, nfo:FileDataObject ; 
         nie:isStoredAs <file:///home/path/file> ; 
         nie:url 'file:///home/path/file' 
}"

tracker-sparql -u -q "INSERT {
  _:tag a nao:Tag ;
        nao:prefLabel 'mylabel' .
  ?unknown nao:hasTag _:tag  
} WHERE {
  ?unknown nie:isStoredAs ?as .
  ?as nie:url 'file:///home/path/file'
}"

tracker-sparql -q "SELECT ?tags ?labels 
WHERE {
  ?f nie:isStoredAs ?d ;
     nao:hasTag ?tags .
  ?d nie:url <file:///home/path/file> .
  ?tags a nao:Tag ;
     nao:prefLabel ?labels .
} ORDER BY ASC(?labels)"
Result: 1
  urn:uuid:YYY-XXX-..., mylabel

Any kind of resource:

tracker-sparql -u -q "INSERT { <urn:XXX:ZZZ> a rdfs:Resource }"

# This assumes the tag already exists from example above
tracker-sparql -u -q "INSERT { 
  <urn:XXX:ZZZ> nao:hasTag ?id 
} WHERE {
  ?id nao:prefLabel 'mylabel' 
}"

tracker-sparql -q "SELECT ?label 
WHERE { 
  <urn:XXX:ZZZ> nao:hasTag ?tag .
  ?tag nao:prefLabel ?label 
}"
Result: 1
  mylabel

Projects/Tracker/Documentation/Examples/SPARQL/Tagging (last edited 2013-11-25 12:54:23 by WilliamJonMcCann)