Commit e120eec0 by Hut

cleanup

parent c8bfdb8d
......@@ -6,12 +6,12 @@
<groupId>passive.directory</groupId>
<artifactId>markov</artifactId>
<version>0.4</version>
<version>0.5</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.9</java.version>
<java.version>1.8</java.version>
<junit.jupiter.version>5.0.3</junit.jupiter.version>
<junit.platform.version>1.0.3</junit.platform.version>
</properties>
......@@ -109,7 +109,7 @@
<configuration>
<archive>
<manifest>
<mainClass>markov.Mail</mainClass>
<mainClass>markov.stuff.Mail</mainClass>
</manifest>
</archive>
<descriptorRefs>
......
package markov;
package markov.stuff;
import com.google.common.base.Stopwatch;
import directory.passive.huffman.ByteHuffmanCodeBuilder;
import directory.passive.huffman.HuffmanCode;
import markov.Builder;
import markov.Data;
import markov.Sentence;
import markov.Shortener;
import markov.huffman.HuffmanStore;
import markov.shortener.ShortenerByteHUffmanTrainerImpl;
import markov.shortener.ShortenerByteHuffmanImpl;
import markov.shortener.ShortenerIntHuffmanImpl;
import markov.shortener.ShortenerSimpleImpl;
import markov.stuff.CountMap;
import markov.stuff.Inspector;
import markov.stuff.SimpleCountMap;
import markov.stuff.Utils;
import java.io.File;
import java.io.FileInputStream;
......@@ -43,7 +43,7 @@ public class Mail {
public static void main(String[] args)
throws IOException, ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
System.in.read();
new Mail().timeCreation();
new Mail().createHuffmanMaps();
}
private void timeCreation() {
......
package markov;
package markov.stuff;
import markov.stuff.Utils;
import markov.Builder;
import markov.Data;
import markov.Renderer;
import markov.Sentence;
import java.util.stream.Stream;
......@@ -9,7 +12,6 @@ public class Main {
public static void main(String[] args) {
int prefixLength = 2;
// Data data = new Parser_first_version(prefixLength).parse(input);
Data data = Utils.parse(Stream.of(input.replace("Kai☺UWE empfiehlt ", "").split("\n")), prefixLength);
Builder b = new Builder(prefixLength, data);
......@@ -20,7 +22,6 @@ public class Main {
System.out.println(r2.render(sentence));
}
// Collection<Map.Entry<Prefix, Decission>> a = b.average();
// System.out.println("average: " + r.render(a));
// for (Map.Entry<Prefix, Decission> e : a) {
......
......@@ -10,7 +10,6 @@ import javax.mail.Session;
import javax.mail.internet.MimeMessage;
import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.ByteBuffer;
......@@ -46,26 +45,16 @@ public class Utils {
public static Data parse(Stream<String> input, int prefixLength) {
Collection<Integer> collectionDummy = new ArrayList<>();
collectionDummy.add(prefixLength);
return new Parser().parse(new Tokenizer().tokenize(input), collectionDummy).values()
.stream().findFirst().get();
return new Parser().parse(new Tokenizer().tokenize(input), collectionDummy)
.values()
.stream()
.findFirst()
.get();
}
public static File getFile(String location) {
File file;
if (location.startsWith("classpath:")) {
URL url = Utils.class.getClassLoader().getResource(location.replace("classpath:", ""));
try {
file = new File(url.toURI());
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
} else {
file = new File(location);
}
if (!file.exists() || !file.canRead() || !file.canWrite()) {
throw new IllegalArgumentException(String.format("could not not use file: %s", file.getName()));
}
return file;
public static Map<Integer, Data> createDataMap(int maxPrefix) {
return createDataMap(maxPrefix,
getFile(System.getProperty("mail.folder", "C:\\Users\\admin\\Desktop\\emails")));
}
public static void maybePrintPercentages(final int i, final int max) {
......@@ -92,34 +81,20 @@ public class Utils {
}
}
public static Map<Integer, Data> deserializeDataMap() throws IOException,
ClassNotFoundException {
System.out.println("reading map");
Map<Integer, Data> dataMap = (Map<Integer, Data>) new ObjectInputStream(
Files.newInputStream(new File(
"C:\\Users\\admin\\git\\markovdisplay\\target\\classes\\data").toPath()))
.readObject();
System.out.println("read map");
return dataMap;
}
public static Map<Integer, Data> createDataMap(int maxPrefix) {
return createDataMap(maxPrefix, new File("C:\\Users\\admin\\Desktop\\emails"));
}
public static Map<Integer, Data> createDataMap(int maxPrefix, File parent) {
System.out.println("generating data map...");
Stream<String> mails = Arrays.stream(parent.listFiles()).limit(500).map(File::toPath).map
(path -> {
try {
Stream<String> mails = Arrays.stream(parent.listFiles()).limit(500).map(File::toPath).map(
path -> {
try {
MimeMessage m = new MimeMessage(
Session.getDefaultInstance(new Properties()), Files.newInputStream(path));
return m;
} catch (IOException | MessagingException e) {
throw new RuntimeException(e);
}
}).filter(mimeMessage -> {
MimeMessage m =
new MimeMessage(Session.getDefaultInstance(new Properties()),
Files.newInputStream(path));
return m;
} catch (IOException | MessagingException e) {
throw new RuntimeException(e);
}
}).filter(mimeMessage -> {
try {
return mimeMessage.getContentType().contains("text/plain");
} catch (MessagingException e) {
......@@ -136,9 +111,28 @@ public class Utils {
Tokenizer tokenizer = new Tokenizer();
Stream<Stream<Token>> tokens = tokenizer.tokenize(mails);
Map<Integer, Data> ret = parser.parse(tokens, IntStream.range(1, maxPrefix + 1)
.boxed()
.collect(Collectors.toList()));
.boxed()
.collect(Collectors.toList()));
System.out.println("generated data map!");
return ret;
}
public static File getFile(String location) {
File file;
if (location.startsWith("classpath:")) {
URL url = Utils.class.getClassLoader().getResource(location.replace("classpath:", ""));
try {
file = new File(url.toURI());
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
} else {
file = new File(location);
}
if (!file.exists() || !file.canRead() || !file.canWrite()) {
throw new IllegalArgumentException(String.format("could not not use file: %s",
file.getName()));
}
return 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