-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_annot.py
54 lines (46 loc) · 2.16 KB
/
gen_annot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# !/usr/local/bin/python
# -*- coding: utf-8 -*-
from os.path import basename, dirname, realpath, splitext
import glob
from rdflib import Graph, Namespace, Literal
from rdflib.namespace import DC, DCTERMS, FOAF, RDF, RDFS, SKOS, XSD
AO = Namespace("http://vitali.web.cs.unibo.it/AnnOtaria/")
AON = Namespace("http://vitali.web.cs.unibo.it/AnnOtaria/annotation/")
AOP = Namespace("http://vitali.web.cs.unibo.it/AnnOtaria/person/")
CITO = Namespace("http://purl.org/spar/cito/")
FABIO = Namespace("http://purl.org/spar/fabio/")
FRBR = Namespace("http://purl.org/vocab/frbr/core#")
OA = Namespace("http://www.w3.org/ns/oa#")
SCHEMA = Namespace("http://schema.org/")
SEM = Namespace("http://www.ontologydesignpatterns.org/cp/owl/semiotics.owl#")
initNS = {'ao': AO, 'aon': AON, 'aop': AOP, 'cito': CITO, 'dc': DC, 'dcterms': DCTERMS, 'fabio': FABIO, 'foaf': FOAF,
'frbr': FRBR, 'oa': OA, 'rdf': RDF, 'rdfs': RDFS, 'schema': SCHEMA, 'sem': SEM, 'skos': SKOS, 'xsd': XSD}
graph = Graph()
for ns in initNS:
graph.bind(ns, initNS[ns])
path = dirname(realpath(__file__))
for f in glob.glob(path + "/annotaria/articles/*.html"):
if basename(f) != "index.html": # skip index
docname, docext = splitext(basename(f))
item = AO[basename(f)]
work = AO[docname]
expression = AO[docname + '_ver1']
graph.add((work, RDF.type, FABIO.Work))
graph.add((work, FABIO.hasPortrayal, item))
graph.add((work, FRBR.realization, expression))
graph.add((expression, RDF.type, FABIO.Expression))
graph.add((expression, FABIO.hasRepresentation, item))
graph.add((item, RDF.type, FABIO.Item))
# add some people
p = AOP['ciromattia-gonano']
graph.add((p, RDF.type, FOAF.Person))
graph.add((p, SCHEMA.email, Literal('[email protected]')))
graph.add((p, FOAF.name, Literal('Ciro Mattia Gonano')))
p = AOP['fabio-vitali']
graph.add((p, RDF.type, FOAF.Person))
graph.add((p, SCHEMA.email, Literal('[email protected]')))
graph.add((p, FOAF.name, Literal('Fabio Vitali')))
p = AOP['pedro']
graph.add((p, RDF.type, FOAF.Person))
graph.add((p, FOAF.name, Literal('Pedro Madrigal')))
graph.serialize('test_annotations.ttl', format='turtle')