Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suggestible
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
Suggestible
Commits
5ebce499
Commit
5ebce499
authored
8 months ago
by
Phil Höfer
Browse files
Options
Downloads
Patches
Plain Diff
Implement Exclusion List For Suggested Terms
parent
1f44ba21
No related branches found
No related tags found
1 merge request
!7
Resolve "Implement Filters for Trait-based Predictors"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
config.toml
+2
-1
2 additions, 1 deletion
config.toml
src/predictors/basic_markov.rs
+21
-3
21 additions, 3 deletions
src/predictors/basic_markov.rs
with
23 additions
and
4 deletions
config.toml
+
2
−
1
View file @
5ebce499
auth
=
"12345"
term_frequency_threshold
=
2
max_predict_count
=
5
\ No newline at end of file
max_predict_count
=
5
blocked_words
=
""
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/predictors/basic_markov.rs
+
21
−
3
View file @
5ebce499
...
...
@@ -34,8 +34,18 @@ impl Predictor for MarkovChainPredictor {
}
fn
update
(
&
mut
self
,
query
:
&
str
)
->
Result
<
(),
Box
<
dyn
std
::
error
::
Error
>>
{
let
blocklist
:
Vec
<&
str
>
=
match
self
.configuration
.get
(
"blocked_words"
)
{
Some
(
list
)
=>
{
list
.split_whitespace
()
.collect
()
},
_
=>
Vec
::
new
()
};
//println!("blocklist:{:?}",self.configuration);
let
lowercase_query
=
query
.to_lowercase
();
let
words
:
Vec
<&
str
>
=
lowercase_query
.split_whitespace
()
.collect
();
let
words
:
Vec
<&
str
>
=
lowercase_query
.split_whitespace
()
.
filter
(|
&
x
|
!
blocklist
.contains
(
&
x
))
.
collect
();
for
window
in
words
.windows
(
2
)
{
if
let
[
first
,
second
]
=
window
{
self
.chain
...
...
@@ -107,14 +117,22 @@ pub fn from_file_path(file_path: &str) -> Result<MarkovChainPredictor, std::io::
pub
fn
from_file_path_and_config
(
file_path
:
&
str
,
config
:
HashMap
<
String
,
impl
Into
<
String
>>
)
->
Result
<
MarkovChainPredictor
,
std
::
io
::
Error
>
{
let
mut
markov_chain
:
MarkovChainPredictor
=
from_file_path
(
file_path
)
?
;
let
mut
configuration
=
HashMap
::
new
();
for
(
key
,
value
)
in
config
{
configuration
.insert
(
key
,
value
.into
());
}
let
file
=
File
::
open
(
file_path
)
?
;
let
mut
reader
=
ReaderBuilder
::
new
()
.from_reader
(
file
);
let
mut
markov_chain
:
MarkovChainPredictor
=
MarkovChainPredictor
::
new
();
markov_chain
.configuration
=
configuration
;
println!
(
"{}"
,
markov_chain
.configuration
.get
(
"term_frequency_threshold"
)
.unwrap
());
for
result
in
reader
.records
()
{
let
record
=
result
?
;
if
let
Some
(
query
)
=
record
.get
(
5
)
{
markov_chain
.update
(
query
);
}
}
Ok
(
markov_chain
)
}
\ No newline at end of file
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
register
or
sign in
to comment