Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
quotsie
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Joschua "λ" Kesper
quotsie
Commits
3584e3fe
Unverified
Commit
3584e3fe
authored
11 months ago
by
Joschua Kesper
Browse files
Options
Downloads
Patches
Plain Diff
Removed quotes appearing in source from markov generated
parent
13bcae88
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
quotes.txt
+3
-2
3 additions, 2 deletions
quotes.txt
src/main.rs
+4
-1
4 additions, 1 deletion
src/main.rs
src/markov.rs
+18
-9
18 additions, 9 deletions
src/markov.rs
with
25 additions
and
12 deletions
quotes.txt
+
3
−
2
View file @
3584e3fe
lorem
ipsum
\ No newline at end of file
a a b
b a c
c a b c
This diff is collapsed.
Click to expand it.
src/main.rs
+
4
−
1
View file @
3584e3fe
...
...
@@ -47,7 +47,10 @@ impl Api {
#[oai(path
=
"/markov"
,
method
=
"get"
)]
async
fn
markov
(
&
self
)
->
PlainText
<
String
>
{
PlainText
(
self
.markov_model
.generage_message
())
match
self
.markov_model
.generage_message
()
{
Ok
(
quote
)
=>
PlainText
(
quote
),
Err
(
err
)
=>
PlainText
(
err
.to_string
()),
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/markov.rs
+
18
−
9
View file @
3584e3fe
use
std
::{
collections
::
HashMap
,
hash
::
Hash
};
use
std
::{
collections
::
{
HashMap
,
HashSet
},
hash
::
Hash
,
result
::
Result
};
use
rand
::
Rng
;
#[derive(Hash,
Clone,
PartialEq,
Eq,
Debug)]
...
...
@@ -42,18 +42,21 @@ impl TokenSampler {
#[derive(Clone)]
pub
struct
Model
{
messages
:
HashSet
<
String
>
,
token_to_token_sampler
:
HashMap
<
Token
,
TokenSampler
>
}
impl
Model
{
pub
fn
new
()
->
Model
{
Model
{
messages
:
HashSet
::
new
(),
token_to_token_sampler
:
HashMap
::
new
()
}
}
pub
fn
add_messages
(
&
mut
self
,
messages
:
&
Vec
<
String
>
)
{
for
message
in
messages
{
self
.messages
.insert
(
message
.to_string
());
self
.add_tokenized_message
(
&
Model
::
tokenize
(
message
));
}
}
...
...
@@ -73,17 +76,23 @@ impl Model {
}
}
pub
fn
generage_message
(
&
self
)
->
String
{
pub
fn
generage_message
(
&
self
)
->
Result
<
String
,
&
'static
str
>
{
let
mut
current_token
=
Token
::
Start
;
let
mut
current_message
=
""
.to_owned
();
for
_
in
1
..
5
{
loop
{
let
next_token
=
self
.token_to_token_sampler
[
&
current_token
]
.sample
();
match
&
next_token
{
Token
::
Start
=>
unreachable!
(
"Start token should not be reachable inside a message :("
),
Token
::
End
=>
re
turn
current_message
,
Token
::
End
=>
b
re
ak
,
Token
::
Word
(
current_word
)
=>
current_message
=
current_message
+
" "
+
&
current_word
}
current_token
=
next_token
;
}
if
!
self
.messages
.contains
(
current_message
.trim
())
{
return
Ok
(
current_message
);
}
}
Err
(
"
\"
Too many matches with source quotes
\"
~λ"
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment