nothing@0: #formal concept analysis nothing@0: nothing@0: import rdflib nothing@0: from rdflib import plugin, OWL nothing@0: from rdflib.graph import Graph nothing@0: from rdflib.namespace import Namespace nothing@0: nothing@0: execfile('/Users/alo/MusicOntology/features/fca/writeHTML.py') nothing@0: nothing@0: plugin.register( nothing@0: 'sparql', rdflib.query.Processor, nothing@0: 'rdfextras.sparql.processor', 'Processor') nothing@0: plugin.register( nothing@0: 'sparql', rdflib.query.Result, nothing@0: 'rdfextras.sparql.query', 'SPARQLQueryResult') nothing@0: nothing@0: graph = Graph() nothing@0: graph.parse('/Users/alo/MusicOntology/features/featuresCatalogue.rdf') nothing@0: nothing@0: res = graph.query( nothing@0: """SELECT DISTINCT ?tool nothing@0: WHERE { nothing@0: ?x local:computedIn ?tool . nothing@0: ?x local:feature ?feature nothing@0: } nothing@0: ORDER BY ?tool""", nothing@0: initNs=dict( nothing@0: local=Namespace("http://sovarr.c4dm.eecs.qmul.ac.uk/features/")) nothing@0: ) nothing@0: nothing@0: cols = [] nothing@0: nothing@0: for it in res: nothing@0: cols.append(it[0]) nothing@0: nothing@0: res = graph.query( nothing@0: """SELECT DISTINCT ?feature nothing@0: WHERE { nothing@0: ?x local:computedIn ?tool . nothing@0: ?x local:feature ?feature nothing@0: } nothing@0: ORDER BY ?feature""", nothing@0: initNs=dict( nothing@0: local=Namespace("http://sovarr.c4dm.eecs.qmul.ac.uk/features/")) nothing@0: ) nothing@0: nothing@0: rows = [] nothing@0: nothing@0: for it in res: nothing@0: rows.append(it[0]) nothing@0: nothing@0: colmap = {} nothing@0: nothing@0: for i in range(len(cols)): nothing@0: it = cols[i] nothing@0: colmap[it] = i nothing@0: nothing@0: rowmap = {} nothing@0: nothing@0: for i in range(len(rows)): nothing@0: it = rows[i] nothing@0: rowmap[it] = i nothing@0: nothing@0: res = graph.query( nothing@0: """SELECT DISTINCT ?feature ?tool nothing@0: WHERE { nothing@0: ?x local:computedIn ?tool . nothing@0: ?x local:feature ?feature nothing@0: } nothing@0: ORDER BY ?feature""", nothing@0: initNs=dict( nothing@0: local=Namespace("http://sovarr.c4dm.eecs.qmul.ac.uk/features/"))) nothing@0: nothing@0: afmatrix = [] nothing@0: nothing@0: for i in range(len(rows)): nothing@0: row = [] nothing@0: for j in range(len(cols)): nothing@0: row.append(0) nothing@0: afmatrix.append(row) nothing@0: nothing@0: for it in res: nothing@0: afmatrix[rowmap[it[0]]][colmap[it[1]]] = 1 nothing@0: nothing@0: nothing@0: #writeHTML('afmatrix.html', afmatrix, cols, rows ) nothing@0: #writeWikiTable('featureToolWiki.txt', afmatrix, cols, rows ) nothing@0: writeLatexTable('featureToolLatex.txt', afmatrix, cols, rows) nothing@0: