Mercurial > hg > audio-features-catalogue
view fca/featureToolMatrix.py @ 0:62d2c72e4223
initial commit
author | nothing@tehis.net |
---|---|
date | Mon, 25 Feb 2013 14:40:54 +0000 |
parents | |
children |
line wrap: on
line source
#formal concept analysis import rdflib from rdflib import plugin, OWL from rdflib.graph import Graph from rdflib.namespace import Namespace execfile('/Users/alo/MusicOntology/features/fca/writeHTML.py') plugin.register( 'sparql', rdflib.query.Processor, 'rdfextras.sparql.processor', 'Processor') plugin.register( 'sparql', rdflib.query.Result, 'rdfextras.sparql.query', 'SPARQLQueryResult') graph = Graph() graph.parse('/Users/alo/MusicOntology/features/featuresCatalogue.rdf') res = graph.query( """SELECT DISTINCT ?tool WHERE { ?x local:computedIn ?tool . ?x local:feature ?feature } ORDER BY ?tool""", initNs=dict( local=Namespace("http://sovarr.c4dm.eecs.qmul.ac.uk/features/")) ) cols = [] for it in res: cols.append(it[0]) res = graph.query( """SELECT DISTINCT ?feature WHERE { ?x local:computedIn ?tool . ?x local:feature ?feature } ORDER BY ?feature""", initNs=dict( local=Namespace("http://sovarr.c4dm.eecs.qmul.ac.uk/features/")) ) rows = [] for it in res: rows.append(it[0]) colmap = {} for i in range(len(cols)): it = cols[i] colmap[it] = i rowmap = {} for i in range(len(rows)): it = rows[i] rowmap[it] = i res = graph.query( """SELECT DISTINCT ?feature ?tool WHERE { ?x local:computedIn ?tool . ?x local:feature ?feature } ORDER BY ?feature""", initNs=dict( local=Namespace("http://sovarr.c4dm.eecs.qmul.ac.uk/features/"))) afmatrix = [] for i in range(len(rows)): row = [] for j in range(len(cols)): row.append(0) afmatrix.append(row) for it in res: afmatrix[rowmap[it[0]]][colmap[it[1]]] = 1 #writeHTML('afmatrix.html', afmatrix, cols, rows ) #writeWikiTable('featureToolWiki.txt', afmatrix, cols, rows ) writeLatexTable('featureToolLatex.txt', afmatrix, cols, rows)