comparison fca/featureToolMatrix.py @ 0:62d2c72e4223

initial commit
author nothing@tehis.net
date Mon, 25 Feb 2013 14:40:54 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:62d2c72e4223
1 #formal concept analysis
2
3 import rdflib
4 from rdflib import plugin, OWL
5 from rdflib.graph import Graph
6 from rdflib.namespace import Namespace
7
8 execfile('/Users/alo/MusicOntology/features/fca/writeHTML.py')
9
10 plugin.register(
11 'sparql', rdflib.query.Processor,
12 'rdfextras.sparql.processor', 'Processor')
13 plugin.register(
14 'sparql', rdflib.query.Result,
15 'rdfextras.sparql.query', 'SPARQLQueryResult')
16
17 graph = Graph()
18 graph.parse('/Users/alo/MusicOntology/features/featuresCatalogue.rdf')
19
20 res = graph.query(
21 """SELECT DISTINCT ?tool
22 WHERE {
23 ?x local:computedIn ?tool .
24 ?x local:feature ?feature
25 }
26 ORDER BY ?tool""",
27 initNs=dict(
28 local=Namespace("http://sovarr.c4dm.eecs.qmul.ac.uk/features/"))
29 )
30
31 cols = []
32
33 for it in res:
34 cols.append(it[0])
35
36 res = graph.query(
37 """SELECT DISTINCT ?feature
38 WHERE {
39 ?x local:computedIn ?tool .
40 ?x local:feature ?feature
41 }
42 ORDER BY ?feature""",
43 initNs=dict(
44 local=Namespace("http://sovarr.c4dm.eecs.qmul.ac.uk/features/"))
45 )
46
47 rows = []
48
49 for it in res:
50 rows.append(it[0])
51
52 colmap = {}
53
54 for i in range(len(cols)):
55 it = cols[i]
56 colmap[it] = i
57
58 rowmap = {}
59
60 for i in range(len(rows)):
61 it = rows[i]
62 rowmap[it] = i
63
64 res = graph.query(
65 """SELECT DISTINCT ?feature ?tool
66 WHERE {
67 ?x local:computedIn ?tool .
68 ?x local:feature ?feature
69 }
70 ORDER BY ?feature""",
71 initNs=dict(
72 local=Namespace("http://sovarr.c4dm.eecs.qmul.ac.uk/features/")))
73
74 afmatrix = []
75
76 for i in range(len(rows)):
77 row = []
78 for j in range(len(cols)):
79 row.append(0)
80 afmatrix.append(row)
81
82 for it in res:
83 afmatrix[rowmap[it[0]]][colmap[it[1]]] = 1
84
85
86 #writeHTML('afmatrix.html', afmatrix, cols, rows )
87 #writeWikiTable('featureToolWiki.txt', afmatrix, cols, rows )
88 writeLatexTable('featureToolLatex.txt', afmatrix, cols, rows)
89