|
Revision 136, 1.1 kB
(checked in by phil, 6 months ago)
|
|
RDFAlchemy added descriptors for locale and some tests
|
| Line | |
|---|
| 1 | from rdfalchemy import Namespace,rdfSingle,rdfMultiple |
|---|
| 2 | from rdfalchemy.rdfsSubject import rdfsSubject |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | DC = Namespace('http://purl.org/dc/terms/') |
|---|
| 6 | BIBO = Namespace('http://purl.org/ontology/bibo/') |
|---|
| 7 | FOAF = Namespace('http://xmlns.com/foaf/0.1/') |
|---|
| 8 | SKOS = Namespace('http://www.w3.org/2004/02/skos/core#') |
|---|
| 9 | |
|---|
| 10 | class Document(rdfsSubject): |
|---|
| 11 | rdf_type = BIBO.Document |
|---|
| 12 | title = rdfSingle(DC['title']) |
|---|
| 13 | alt_titles = rdfMultiple(DC.alt) |
|---|
| 14 | date = rdfSingle(DC.date) |
|---|
| 15 | issued = rdfSingle(DC.issued) |
|---|
| 16 | modified = rdfSingle(DC.modified) |
|---|
| 17 | creators = rdfMultiple(DC.creator) |
|---|
| 18 | authorList = rdfMultiple(BIBO.authorList) |
|---|
| 19 | subjects = rdfMultiple(DC.subject, range_type=SKOS.Concept) |
|---|
| 20 | |
|---|
| 21 | class Book(Document): |
|---|
| 22 | rdf_type = BIBO.Book |
|---|
| 23 | publisher = rdfSingle(DC.publisher,range_type=FOAF.Organization) |
|---|
| 24 | series = rdfSingle(DC.isPartOf, range_type=BIBO.Series) |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | x = Book(title="Some Title") |
|---|
| 28 | y = Document(title="Another Title") |
|---|
| 29 | |
|---|
| 30 | def len_test(): |
|---|
| 31 | assert len(list(Document.ClassInstances())) == 2, "wanted 2 ... one book and one document" |
|---|
| 32 | |
|---|
| 33 | for document in Document.ClassInstances(): |
|---|
| 34 | print document.title |
|---|
| 35 | |
|---|