W3C home > Mailing lists > Public > semantic-web@w3.org > September 2007

mopy announcement

From: Chris Sutton <lists@chrissutton.org>
Date: Fri, 21 Sep 2007 11:44:42 +0100
Message-ID: <46F3A09A.50805@chrissutton.org>
To: semantic-web@w3.org

Hi all,

(apologies for cross-posting)

I'm pleased to announce the first real release of mopy, the Music
Ontology Python library. Despite the name, mopy can handle information
from several ontologies, including the full FOAF vocab, and the timeline
and chord ontologies.

mopy 0.2 can be downloaded from :


and more information is available in the readme file here :


mopy provides natural python bindings for dealing with RDF data, so that
instead of :

>>> import rdflib
>>> from rdflib import URIRef, Literal, BNode, RDF, RDFS, Namespace
>>> g = rdflib.ConjunctiveGraph()
>>> MO_ns = Namespace("http://purl.org/ontology/mo/")
>>> FOAF_ns = Namespace("http://xmlns.com/foaf/0.1/")
>>> band1 = URIRef("http://band1.com/us")
>>> g.add((band1, RDF.type, FOAF_ns["MusicGroup"]))
>>> g.add((band1, RDFS.label, Literal("awesome band")))
>>> g.add((band1, FOAF_ns["name"], Literal("DEATH MONKEYS")))
>>> member_names = ["Baz", "Bill", "Bob", "Clifton"]
>>> for m in member_names:
....	b = BNode()
....	g.add((b, RDF.type, MO_ns["SoloMusicArtist"]))
....	g.add((b, FOAF_ns["name"], Literal(m)))
....	g.add((band1, MO_ns["member"], b))

you can simply write :

>>> import mopy
>>> band1 = mopy.mo.MusicGroup("http://band1.com/us")
>>> band1.label = "awesome band"
>>> band1.name = "DEATH MONKEYS"
>>> member_names = ["Baz", "Bill", "Bob", "Clifton"]
>>> for m in member_names:
....     member = mopy.mo.SoloMusicArtist()
....     member.name = m
....     band1.member.add(member)

mopy supports reading and writing of RDF in XML or N3 format, and
performs simple type (and typo !) checking, to make sure that the data
you create or manipulate is using the supported ontologies correctly.
For example, trying to set and rdf:lable instead of an rdf:label will
produce an error, as will trying to add a chord as the object of a
foaf:knows :

>>> me = mopy.foaf.Person("http://chrissutton.org/me")
>>> me.lable = "just this guy, you know ?"
Traceback (most recent call last):
AttributeError: Not allowed add new attributes to classes ! Typo ?

>>> Cmaj = mopy.chord.Chord()
>>> Cmaj.root = mopy.note.C
>>> Cmaj.base_chord = mopy.chord.maj
>>> me.knows = Cmaj
Traceback (most recent call last):
TypeError: Invalid type ! Got <class 'mopy.model.chord___Chord'> but
expected one of : <class 'mopy.model.foaf___Person'>

(In fact, creating this example, I was forcefully reminded that it's
chord:base_chord, not chord:baseChord !)

There's work still to be done on mopy, but it's usable now, and we're
keen to receive any feedback.

Though it is intended primarily to help development of tools which use
the Music Ontology, the way mopy is produced is very flexible - if you
have suggestions of related ontologies which could be usefully included,
please let us know.


Chris Sutton
Received on Monday, 24 September 2007 04:47:55 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 1 March 2016 07:41:59 UTC