-
Notifications
You must be signed in to change notification settings - Fork 3
/
ic.dl
50 lines (35 loc) · 2 KB
/
ic.dl
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
#define RDFS_SUBCLASS_OF "<http://www.w3.org/2000/01/rdf-schema#subClassOf>"
#define REFERENCE_COUNT "<http://reasoner.renci.org/vocab/referenceCount>"
#define HAS_NORMALIZED_IC "<http://reasoner.renci.org/vocab/normalizedInformationContent>"
#define HAS_NORMALIZED_SUBCLASS_IC "<http://reasoner.renci.org/vocab/normalizedSubClassInformationContent>"
.functor logn(x: float): float
.decl rdf(s: symbol, p: symbol, o: symbol)
.decl references(sub: symbol, super: symbol)
.decl subClassOf(sub: symbol, super: symbol)
.decl term(t: symbol)
.decl totalTerms(c: number)
.decl referenceCount(term: symbol, c: number)
.decl subClassOfReferenceCount(term: symbol, c: number)
.decl maxIC(n: float)
.decl normalizedIC(term: symbol, ic: float)
.decl normalizedSubClassOfIC(term: symbol, ic: float)
.decl icRDF(term: symbol, predicate: symbol, ic: float, dot: symbol)
.decl subClassOfICRDF(term: symbol, predicate: symbol, ic: float, dot: symbol)
.decl scRDF(term: symbol, predicate: symbol, c: number, dot: symbol)
references(sub, super) :- rdf(sub, _, super).
subClassOf(sub, super) :- rdf(sub, RDFS_SUBCLASS_OF, super).
term(t) :- references(t, _).
totalTerms(c) :- c = count : { term(_) }.
referenceCount(t, c) :- term(t), c = count : { references(_, t) }.
subClassOfReferenceCount(t, c) :- term(t), c = count : { subClassOf(_, t) }.
maxIC(-@logn(1.0/to_float(n))) :- totalTerms(n).
normalizedIC(t, (-@logn(to_float(c)/to_float(total)))*scale) :- referenceCount(t, c), totalTerms(total), maxIC(maxic), scale=100.0/maxic.
normalizedSubClassOfIC(t, (-@logn(to_float(c)/to_float(total)))*scale) :- subClassOfReferenceCount(t, c), totalTerms(total), maxIC(maxic), scale=100.0/maxic.
icRDF(term, HAS_NORMALIZED_IC, ic, ".") :- normalizedIC(term, ic).
subClassOfICRDF(term, HAS_NORMALIZED_SUBCLASS_IC, ic, ".") :- normalizedSubClassOfIC(term, ic).
scRDF(term, REFERENCE_COUNT, c, ".") :- referenceCount(term, c).
// sed 's/ /\t/' <ontology.nt | sed 's/ /\t/' | sed 's/ \.$//' >rdf.facts
.input rdf
.output icRDF
.output subClassOfICRDF
.output scRDF