-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_fca.html
More file actions
93 lines (81 loc) · 2.97 KB
/
test_fca.html
File metadata and controls
93 lines (81 loc) · 2.97 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html>
<head>
<title>Test of FCA framewor</title>
<script src="bvo.js"></script>
<script src="fca.js"></script>
<meta charset="utf-8" />
<style>
*{font-family: Courier;}
</style>
</head>
<body>
<p>Test FCA framework</p>
<p>This uses the example on https://en.wikipedia.org/wiki/Formal_concept_analysis to test the building of a concept lattice</p>
<div id="message"></div>
<div id="lattice"></div>
<script>
var starttime = new Date().getTime();
var inter = {
message: function (m){
console.log(((new Date().getTime()-starttime)/1000)+" - "+m);
document.getElementById("message").innerHTML+="<br>"+
(((new Date().getTime())-starttime)/1000)+" - "+m;
}
}
inter.message("starting");
attributes = ["temporary", "running", "natural", "stagnant", "constant", "maritime"];
objects = ["canal","channel","lagoon","lake","maar","puddle","pond","pool","reservoir","river","rivulet", "runnel","sea","stream","tarn","torrent","trickle"]
matrix = [
[false,true,false,false,true,false],
[false,true,false,false,true,false],
[false,false,true,true,true,true],
[false,false,true,true,true,false],
[false,false,true,true,true,false],
[true,false,true,true,false,false],
[false,false,true,true,true,false],
[false,false,true,true,true,false],
[false,false,false,true,true,false],
[false,true,true,false,true,false],
[false,true,true,false,true,false],
[false,true,true,false,true,false],
[false,false,true,true,true,true],
[false,true,true,false,true,false],
[false,false,true,true,true,false],
[false,true,true,false,true,false],
[false,true,true,false,true,false]]
inter.message("creating context");
var formal_context = new FormalContext(attributes, objects, matrix);
inter.message("building concepts");
formal_context.buildConcepts();
inter.message("creating taxonomy");
formal_context.buildTaxonomy();
inter.message("populating");
formal_context.populate();
inter.message("adding labels");
formal_context.addLabels();
inter.message("done");
console.log(formal_context.root());
console.log(formal_context);
function display(n, i){
var str = '<div style="border: 1px black solid; float: left; width: '+(i==1?100:30)+'%; overflow: auto;">';
str+=n.attributes+'<br/>';
str+=n.extention+'<br/>';
for (var sn in n.subconcepts){
str += display(n.subconcepts[sn], i+1);
}
return str+'</div>';
}
function display2(n,i){
var str=""
for (var j = 0; j < i; j++) str+="--";
str+=n.attributes + "<br>" // +" ("+n.extention+")<br/>";
for (var sn in n.subconcepts){
str += display2(n.subconcepts[sn], i+1);
}
return str;
}
document.getElementById("lattice").innerHTML = display2(formal_context.root(), 1);
</script>
</body>
</html>