1

I'm just entering the semantic world and I can't understand some things. I'm trying to figure out how to check what kind of element is an HTML element based on the Microdata tags on it. I'm working from a Firefox extension, so I have no limitations about requests and the low privileges stuff. I just need to figure it out what is the element about and display an alert in a user comprehensible language (no MusicRecording for example) by knowing the kind of defined "thing" in the schema. Consider this microdata example:

<div itemscope itemtype="http://schema.org/MusicRecording">
  <span itemprop="byArtist" itemscope itemtype="http://schema.org/MusicGroup">
    British rock band 
   <span itemprop="name">Queen</span> 
  </span>
  for their 
  <span itemprop="inAlbum" itemscope itemtype="http://schema.org/MusicAlbum"> 
    <span itemprop="dateCreated">1977</span> album  
    <span itemprop="name">News of the World</span>
  </span>
<div>

By reading the itemtype I need to be able to retrieve the name of the thing (something like "Music Recording"), but not analyzing the string; in a "right way", by querying something and asking for that. The thing is, I can't found a REST api or something like that for obtaining the name, and I need to do it with pure javascript.

So... Any clue/idea? (besides asking the DOM of such URL)

Tomasz Pluskiewicz
  • 3,622
  • 1
  • 19
  • 42
gal007
  • 6,911
  • 8
  • 47
  • 70
  • I’m not sure I understand … For your example markup, you want to get the string "Music Recording" for the `div` with the `itemtype="http://schema.org/MusicRecording"`? So you need the label of the itemtype? – unor Jan 21 '16 at 12:46
  • @unor yes, that is the point. Now i'm realizing maybe it is not as easy as it seems, because you can retrieve such associated file data but... hey, it's no label defined :( – gal007 Jan 21 '16 at 14:26

2 Answers2

1

I think the RDF translator app will help you. In addition to a UI it exposes a REST Service, which you can use to convert Microdata to other RDF serializations, like turtle etc. You will then be able to interrogate that data with SPARQL. There are implementations for any language you could imagine.

Alternatively there may be a library which understands Microdata directly, but I'm not sure about that.

Tomasz Pluskiewicz
  • 3,622
  • 1
  • 19
  • 42
1

The canonical machine-readable representation of the Schema.org vocabulary is in RDFa: http://schema.org/docs/schema_org_rdfa.html

In this file, each Schema.org type (rdfs:Class) has a value for the rdfs:label property, which "may be used to provide a human-readable version of a resource's name".

However, it seems that the Schema.org team decided to provide the label like it’s given in the URL, so for http://schema.org/MusicRecording it’s "MusicRecording", not "Music recording":

<div typeof="rdfs:Class" resource="http://schema.org/MusicRecording">
  <span class="h" property="rdfs:label">MusicRecording</span>
  <span property="rdfs:comment">A music recording (track), usually a single song.</span>
   <span>Subclass of: <a property="rdfs:subClassOf" href="http://schema.org/CreativeWork">CreativeWork</a></span>
</div>
Community
  • 1
  • 1
unor
  • 92,415
  • 26
  • 211
  • 360