Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
markov
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Patrick Friedel
markov
Commits
e120eec0
Commit
e120eec0
authored
Apr 06, 2018
by
Hut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup
parent
c8bfdb8d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
59 deletions
+54
-59
pom.xml
pom.xml
+3
-3
Mail.java
src/main/java/markov/stuff/Mail.java
+6
-6
Main.java
src/main/java/markov/stuff/Main.java
+5
-4
Utils.java
src/main/java/markov/stuff/Utils.java
+40
-46
huffmanBytes
src/main/resources/huffmanBytes
+0
-0
huffmanInts
src/main/resources/huffmanInts
+0
-0
No files found.
pom.xml
View file @
e120eec0
...
...
@@ -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>
...
...
src/main/java/markov/Mail.java
→
src/main/java/markov/
stuff/
Mail.java
View file @
e120eec0
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
()
{
...
...
src/main/java/markov/Main.java
→
src/main/java/markov/
stuff/
Main.java
View file @
e120eec0
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) {
...
...
src/main/java/markov/stuff/Utils.java
View file @
e120eec0
...
...
@@ -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
;
}
}
src/main/resources/huffmanBytes
View file @
e120eec0
No preview for this file type
src/main/resources/huffmanInts
View file @
e120eec0
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment