Commit 99257c27 by Hut

trigger gitlab CI

parent e03e6f08
...@@ -3,8 +3,11 @@ package directory.passive.markov; ...@@ -3,8 +3,11 @@ package directory.passive.markov;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(input);
System.exit(0);
int prefixLength = 2; int prefixLength = 2;
Data data = new Parser(prefixLength).parse(input); Data data = new Parser_first_version(prefixLength).parse(input);
Builder b = new Builder(prefixLength, data); Builder b = new Builder(prefixLength, data);
Renderer r = new Renderer(data, Renderer.Options.FULL); Renderer r = new Renderer(data, Renderer.Options.FULL);
for (int i = 0; i < 25; i++) { for (int i = 0; i < 25; i++) {
......
package directory.passive.markov; package directory.passive.markov;
public class Parser { public interface Parser {
private final int prefix_length;
public Parser(int prefix_length) {
super();
this.prefix_length = prefix_length;
}
public Data parse(String input) {
Data data = new Data();
for (String line : input.split("\n")) {
line = line.replace("Kai☺UWE empfiehlt ", "");
Token[] tokens = tokenize(line);
for (int i = 0 + prefix_length; i < tokens.length; i++) {
Prefix p = getPrefix(tokens, i);
Token t = getToken(tokens, i);
data.add(p, t);
}
}
return data;
}
private Token[] tokenize(String line) {
String[] strings = line.split(" ");
Token[] tokens = new Token[strings.length + prefix_length + 1];
int i = 0;
for (; i < prefix_length; i++) {
tokens[i] = Token.START;
}
for (; i < strings.length + prefix_length; i++) {
tokens[i] = new Token(strings[i - prefix_length]);
}
tokens[i] = Token.END;
return tokens;
}
private Prefix getPrefix(Token[] tokens, int index) {
Token[] prefixTokens = new Token[prefix_length];
for (int i = 0; i < prefix_length; i++) {
prefixTokens[i] = tokens[index - prefix_length + i];
}
return new Prefix(prefixTokens);
}
private Token getToken(Token[] tokens, int i) {
return tokens[i];
}
} }
package directory.passive.markov;
public class ParserStreamStyle {
}
package directory.passive.markov;
public class Parser_first_version {
private final int prefix_length;
public Parser_first_version(int prefix_length) {
super();
this.prefix_length = prefix_length;
}
public Data parse(String input) {
Data data = new Data();
for (String line : input.split("\n")) {
line = line.replace("Kai☺UWE empfiehlt ", "");
Token[] tokens = tokenize(line);
for (int i = 0 + prefix_length; i < tokens.length; i++) {
Prefix p = getPrefix(tokens, i);
Token t = getToken(tokens, i);
data.add(p, t);
}
}
return data;
}
private Token[] tokenize(String line) {
String[] strings = line.split(" ");
Token[] tokens = new Token[strings.length + prefix_length + 1];
int i = 0;
for (; i < prefix_length; i++) {
tokens[i] = Token.START;
}
for (; i < strings.length + prefix_length; i++) {
tokens[i] = new Token(strings[i - prefix_length]);
}
tokens[i] = Token.END;
return tokens;
}
private Prefix getPrefix(Token[] tokens, int index) {
Token[] prefixTokens = new Token[prefix_length];
for (int i = 0; i < prefix_length; i++) {
prefixTokens[i] = tokens[index - prefix_length + i];
}
return new Prefix(prefixTokens);
}
private Token getToken(Token[] tokens, int i) {
return tokens[i];
}
}
...@@ -9,11 +9,11 @@ public class Prefix { ...@@ -9,11 +9,11 @@ public class Prefix {
private final List<Token> tokens; private final List<Token> tokens;
public Prefix(Token[] tokens) { public Prefix(Token[] tokens) {
this.tokens = Arrays.asList(tokens); this.tokens = compressLeadingStarts(Arrays.asList(tokens));
} }
public Prefix(List<Token> tokens) { public Prefix(List<Token> tokens) {
this.tokens = tokens; this.tokens= compressLeadingStarts(tokens);
} }
public Prefix slide(Token newToken) { public Prefix slide(Token newToken) {
...@@ -23,6 +23,19 @@ public class Prefix { ...@@ -23,6 +23,19 @@ public class Prefix {
return new Prefix(newTokens); return new Prefix(newTokens);
} }
private List<Token> compressLeadingStarts(List<Token> tokens) {
if(tokens.get(0) == Token.START) {
for (int i = 1; i < tokens.size(); i++) {
if (tokens.get(i) == Token.START) {
tokens.remove(i);
}else {
break;
}
}
}
return tokens;
}
@Override @Override
public String toString() { public String toString() {
return "P=" + tokens; return "P=" + tokens;
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>passive.directory</groupId>
<artifactId>markov</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<junit.version>4.12</junit.version>
<junit.jupiter.version>5.0.3</junit.jupiter.version>
<junit.vintage.version>${junit.version}.3</junit.vintage.version>
<junit.platform.version>1.1.0-RC1</junit.platform.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<includes>
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*Tests.java</include>
<include>**/*TestCase.java</include>
</includes>
<properties>
<!-- <includeTags>fast</includeTags> -->
<excludeTags>slow</excludeTags>
<!--
<configurationParameters>
junit.jupiter.conditions.deactivate = *
</configurationParameters>
-->
</properties>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment