nothing@0: #formal concept analysis nothing@0: nothing@0: import rdflib nothing@0: from rdflib import plugin, OWL, URIRef 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: tools = [] 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: for it in res: nothing@0: tools.append(it[0]) nothing@0: nothing@0: tools.sort() nothing@0: nothing@0: features = [] nothing@0: nothing@0: for s, p, o in graph.triples((None, None, OWL.Class)): nothing@0: features.append(s.split('/')[-1]) nothing@0: nothing@0: features.sort() nothing@0: nothing@0: for ns, value in graph.namespaces(): nothing@0: if ns == 'local': nothing@0: local = value nothing@0: nothing@0: similarity = {} nothing@0: nothing@0: for feature in features: nothing@0: mtrx = [] nothing@0: for i in range(len(tools)): nothing@0: row = [] nothing@0: for j in range(len(tools)): nothing@0: row.append(0) nothing@0: mtrx.append(row) nothing@0: similarity[feature] = mtrx nothing@0: for s, p, o in graph.triples((URIRef(local+feature), URIRef(local+'computedIn'), None)): nothing@0: if tools.count(o) != 0: nothing@0: similarity[feature][tools.index(o)][tools.index(o)] = 1 nothing@0: nothing@0: nothing@0: html = '' nothing@0: for feature in features: nothing@0: count = 0 nothing@0: for i in range(len(similarity[feature])): nothing@0: count += similarity[feature][i].count(1) nothing@0: if count > 1: nothing@0: html += '