1: <?php
2:
3:
4: namespace app\controllers;
5:
6: use \mako\http\routing\Controller;
7: use \mako\syringe\ContainerAwareTrait;
8:
9: 10: 11: 12: 13:
14: class AutoLenkingController extends Controller {
15:
16: use ContainerAwareTrait;
17:
18:
19:
20: private function exist($link1, $link2) {
21:
22: if ($link1[0] == $link2[0] || $link1[0] == $link2[1] || $link1[1] == $link2[0] || $link1[1] == $link2[1])
23: return true;
24: else
25: return false;
26: }
27:
28: private function findInCluster($cluster, $link) {
29: $found = false;
30: foreach ($cluster as $unit) {
31:
32: if ($this->exist($unit, $link) === true) {
33:
34:
35: $found = true;
36: break;
37: }
38: }
39: return $found;
40: }
41:
42: private function addLink($clusters, $link) {
43: if (count($clusters) == 0) {
44:
45: $clusters[] = array($link);
46: } else {
47: $found = false;
48: foreach ($clusters as &$cluster) {
49:
50: $found = $this->findInCluster($cluster, $link);
51: if ($found === true) {
52: $cluster[] = $link;
53: break;
54: }
55: }
56: if ($found === false) {
57: $clusters[] = array($link);
58: }
59: }
60: return $clusters;
61: }
62:
63: private function inNewCluster($newcluster, $pfid, $score) {
64: foreach ($newcluster['entries'] as &$entry) {
65: if ($entry[0] == $pfid) {
66: if ($entry[1] > $score) {
67: $entry[1] = $score;
68: return $newcluster;
69: } else {
70: return $newcluster;
71: }
72: }
73: }
74: $newcluster['entries'] [] = array($pfid, $score);
75: return $newcluster;
76: }
77:
78: private function analyseCluster($cluster) {
79: $newcluster = array();
80: if (!empty($cluster)) {
81: $n = sizeof($cluster) - 1;
82: $newcluster['main'] = $cluster[$n][0];
83: $newcluster['entries'] = array();
84: $newcluster['entries'][] = array($cluster[$n][0], '-1');
85: foreach ($cluster as $unit) {
86:
87: $newcluster = $this->inNewCluster($newcluster, $unit[0], $unit[2]);
88: $newcluster = $this->inNewCluster($newcluster, $unit[1], $unit[2]);
89: }
90: }
91: return $newcluster;
92: }
93:
94:
95: private function mergeCluster($cluster)
96: {
97:
98: $user = array("id"=>"11", "marker"=>"a");
99: $pcart = new PersonCart();
100: $pcart->automerge($cluster, $user);
101: }
102:
103: public function lenk() {
104: $filename = "/var/www/hbrutvikling/autolenking/lenkesettQF.txt";
105: $clusters = array();
106:
107: $file = @fopen($filename, "r");
108: if ($file) {
109: while (!feof($file)) {
110: $line = fgets($file, 4096);
111: if ($line) {
112: $link = explode("\t", $line);
113: if (count($link) != 3)
114: continue;
115: else {
116:
117: $clusters = $this->addLink($clusters, $link);
118: }
119: }
120: }
121: fclose($file);
122: $newclusters = array();
123: foreach ($clusters as $cluster) {
124:
125: $newclusters[] = $this->analyseCluster($cluster);
126: }
127:
128: foreach ($newclusters as $cluster)
129: {
130: $this->mergeCluster($cluster);
131: }
132:
133: } else {
134:
135: }
136:
137: return $this->view->render('autolenking.autolenking', array());
138: }
139:
140: }
141: