Skip to content

Commit fbc51f0

Browse files
Added Java sources as reference
1 parent c5bc72b commit fbc51f0

File tree

141 files changed

+13793
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+13793
-0
lines changed

java/core/pom.xml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>aika-project</artifactId>
7+
<groupId>network.aika</groupId>
8+
<version>${revision}</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>aika-core</artifactId>
13+
<version>${revision}</version>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>network.aika</groupId>
18+
<artifactId>aika-fields</artifactId>
19+
</dependency>
20+
21+
<dependency>
22+
<groupId>commons-io</groupId>
23+
<artifactId>commons-io</artifactId>
24+
</dependency>
25+
26+
<!-- Logging -->
27+
<dependency>
28+
<groupId>org.slf4j</groupId>
29+
<artifactId>slf4j-api</artifactId>
30+
</dependency>
31+
32+
<!-- dependencies for tests: -->
33+
<dependency>
34+
<groupId>org.junit.jupiter</groupId>
35+
<artifactId>junit-jupiter-engine</artifactId>
36+
<scope>test</scope>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.junit.jupiter</groupId>
41+
<artifactId>junit-jupiter-params</artifactId>
42+
<scope>test</scope>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>org.junit.jupiter</groupId>
47+
<artifactId>junit-jupiter-api</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>org.mockito</groupId>
53+
<artifactId>mockito-junit-jupiter</artifactId>
54+
<scope>test</scope>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>org.mockito</groupId>
59+
<artifactId>mockito-core</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
63+
<dependency>
64+
<groupId>ch.qos.logback</groupId>
65+
<artifactId>logback-core</artifactId>
66+
<scope>test</scope>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>ch.qos.logback</groupId>
71+
<artifactId>logback-classic</artifactId>
72+
<scope>test</scope>
73+
</dependency>
74+
</dependencies>
75+
</project>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package network.aika;
18+
19+
/**
20+
*
21+
* @author Lukas Molzberger
22+
*/
23+
public class Config {
24+
private Double alpha = null; //0.99;
25+
26+
private double learnRate;
27+
28+
private boolean trainingEnabled;
29+
private boolean countingEnabled;
30+
31+
private long neuronProviderRetention = 50;
32+
33+
private Long timeout;
34+
35+
36+
public double getLearnRate() {
37+
return learnRate;
38+
}
39+
40+
public Config setLearnRate(double learnRate) {
41+
this.learnRate = learnRate;
42+
return this;
43+
}
44+
public Double getAlpha() {
45+
return alpha;
46+
}
47+
48+
public Config setAlpha(Double alpha) {
49+
this.alpha = alpha;
50+
return this;
51+
}
52+
53+
public boolean isTrainingEnabled() {
54+
return trainingEnabled;
55+
}
56+
57+
public Config setTrainingEnabled(boolean trainingEnabled) {
58+
this.trainingEnabled = trainingEnabled;
59+
return this;
60+
}
61+
62+
public Config setCountingEnabled(boolean countingEnabled) {
63+
this.countingEnabled = countingEnabled;
64+
return this;
65+
}
66+
67+
public boolean isCountingEnabled() {
68+
return countingEnabled;
69+
}
70+
71+
public long getNeuronProviderRetention() {
72+
return neuronProviderRetention;
73+
}
74+
75+
public Config setNeuronProviderRetention(long neuronProviderRetention) {
76+
this.neuronProviderRetention = neuronProviderRetention;
77+
return this;
78+
}
79+
80+
public Long getTimeout() {
81+
return timeout;
82+
}
83+
84+
public Config setTimeout(Long timeout) {
85+
this.timeout = timeout;
86+
return this;
87+
}
88+
89+
public String toString() {
90+
return "Alpha: " + alpha + "\n" +
91+
"LearnRate" + learnRate + "\n\n";
92+
}
93+
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package network.aika;
18+
19+
20+
import network.aika.activations.Activation;
21+
import network.aika.bindingsignal.BSType;
22+
import network.aika.bindingsignal.BindingSignal;
23+
import network.aika.neurons.Neuron;
24+
import network.aika.queue.Queue;
25+
import network.aika.queue.QueueProvider;
26+
import network.aika.queue.Step;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
29+
30+
import java.util.*;
31+
import java.util.function.Predicate;
32+
33+
34+
/**
35+
* The {@code Document} class represents a single document which may be either used for processing a text or as
36+
* training input. A document consists of the raw text, the interpretations and the activations.
37+
*
38+
* @author Lukas Molzberger
39+
*/
40+
public class Document extends Queue implements ModelProvider, QueueProvider {
41+
42+
protected static final Logger LOG = LoggerFactory.getLogger(Document.class);
43+
44+
protected final Model model;
45+
46+
private Long id;
47+
48+
private long absoluteBeginChar;
49+
private int length;
50+
51+
private int activationIdCounter = 0;
52+
53+
private final Map<Integer, Activation> activations = new TreeMap<>();
54+
private final TreeMap<Integer, BindingSignal> bindingSignals = new TreeMap<>();
55+
56+
private boolean isStale;
57+
58+
public Document(Model m, int length) {
59+
model = m;
60+
id = model.createThoughtId();
61+
62+
absoluteBeginChar = m.getN();
63+
this.length = length;
64+
65+
m.registerDocument(this);
66+
}
67+
68+
public Long getId() {
69+
return id;
70+
}
71+
72+
@Override
73+
public Long getTimeout() {
74+
return getConfig().getTimeout();
75+
}
76+
77+
public void process(Predicate<Step> filter) {
78+
super.process(filter);
79+
80+
if(model.getConfig().isCountingEnabled())
81+
model.addToN(length);
82+
}
83+
84+
public Model getModel() {
85+
return model;
86+
}
87+
88+
@Override
89+
public Config getConfig() {
90+
return model.getConfig();
91+
}
92+
93+
public Step getCurrentStep() {
94+
return currentStep;
95+
}
96+
97+
public void addActivation(Activation act) {
98+
activations.put(act.getId(), act);
99+
}
100+
101+
public Collection<Activation> getActivations() {
102+
return activations.values();
103+
}
104+
105+
public Activation getActivationByNeuron(Neuron outputNeuron) {
106+
return getActivations().stream()
107+
.filter(act -> act.getNeuron() == outputNeuron)
108+
.findFirst()
109+
.orElse(null);
110+
}
111+
112+
public int createActivationId() {
113+
return activationIdCounter++;
114+
}
115+
116+
public void disconnect() {
117+
model.deregisterDocument(this);
118+
119+
isStale = true;
120+
}
121+
122+
@Override
123+
public Queue getQueue() {
124+
return this;
125+
}
126+
127+
public Activation addToken(Neuron n, BSType bsType, int tokenId) {
128+
BindingSignal bs = getOrCreateBindingSignal(tokenId);
129+
130+
Activation act = n.createActivation(
131+
null,
132+
this,
133+
Map.of(bsType, bs)
134+
);
135+
136+
return act;
137+
}
138+
139+
public BindingSignal getOrCreateBindingSignal(int tokenId) {
140+
return bindingSignals.computeIfAbsent(tokenId, tid ->
141+
new BindingSignal(tid, this)
142+
);
143+
}
144+
145+
public BindingSignal getBindingSignal(Integer tokenId) {
146+
return bindingSignals.get(id);
147+
}
148+
149+
public String toString() {
150+
StringBuilder sb = new StringBuilder();
151+
sb.append(" Id:" + id);
152+
return sb.toString();
153+
}
154+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package network.aika;
18+
19+
20+
import network.aika.queue.Timestamp;
21+
22+
/**
23+
* An Element is either a node (Activation) or an edge (Link) in the Activation graph.
24+
*
25+
* @author Lukas Molzberger
26+
*/
27+
public interface Element {
28+
29+
Timestamp getCreated();
30+
31+
Timestamp getFired();
32+
33+
}

0 commit comments

Comments
 (0)