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
980f1d3c
Commit
980f1d3c
authored
8 months ago
by
Phil Höfer
Browse files
Options
Downloads
Patches
Plain Diff
Allow Reading From Multiple Input Files
parent
672f77d2
No related branches found
No related tags found
No related merge requests found
Pipeline
#9880
passed
8 months ago
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
config.toml
+1
-1
1 addition, 1 deletion
config.toml
src/main.rs
+3
-4
3 additions, 4 deletions
src/main.rs
src/predictors/basic_markov.rs
+19
-7
19 additions, 7 deletions
src/predictors/basic_markov.rs
src/predictors/basic_set.rs
+20
-10
20 additions, 10 deletions
src/predictors/basic_set.rs
with
43 additions
and
22 deletions
config.toml
+
1
−
1
View file @
980f1d3c
auth
=
"12345"
term_frequency_threshold
=
2
term_frequency_threshold
=
1
max_predict_count
=
5
blocked_words
=
""
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/main.rs
+
3
−
4
View file @
980f1d3c
...
...
@@ -38,10 +38,9 @@ fn main() -> Result<(), io::Error> {
}
}
let
markov_chain
=
basic_set
::
from_file_path_and_config
(
"../../data/data.csv"
,
config
.clone
())
.unwrap_or
(
basic_set
::
from_file_path_and_config
(
"data/data.csv"
,
config
.clone
())
.unwrap_or
(
basic_set
::
from_file_path_and_config
(
"data.csv"
,
config
.clone
())
.unwrap_or
(
basic_set
::
SetPredictor
::
new
())));
let
markov_chain
=
basic_markov
::
from_file_path_and_config
(
vec!
[
"../../data/data.csv"
,
"data/data.csv"
,
"data.csv"
],
config
.clone
())
.unwrap_or
(
basic_markov
::
MarkovChainPredictor
::
new
());
// let term_frequency_threshold = match config.get("term_frequency_threshold") {
...
...
This diff is collapsed.
Click to expand it.
src/predictors/basic_markov.rs
+
19
−
7
View file @
980f1d3c
...
...
@@ -116,20 +116,32 @@ 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
>
{
pub
fn
from_file_path_and_config
(
file_path
s
:
Vec
<
&
str
>
,
config
:
HashMap
<
String
,
impl
Into
<
String
>>
)
->
Result
<
MarkovChainPredictor
,
std
::
io
::
Error
>
{
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
;
for
result
in
reader
.records
()
{
let
record
=
result
?
;
if
let
Some
(
query
)
=
record
.get
(
5
)
{
markov_chain
.update
(
query
);
for
path
in
file_paths
{
println!
(
"Trying to open data file at {}"
,
path
);
match
File
::
open
(
path
)
{
Ok
(
file
)
=>
{
println!
(
"Reading data file..."
);
let
mut
reader
=
ReaderBuilder
::
new
()
.from_reader
(
file
);
for
result
in
reader
.records
()
{
let
record
=
result
?
;
if
let
Some
(
query
)
=
record
.get
(
5
)
{
markov_chain
.update
(
query
);
}
}
},
Err
(
e
)
=>
{
println!
(
"Error while reading: {}"
,
e
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/predictors/basic_set.rs
+
20
−
10
View file @
980f1d3c
use
std
::{
collections
::
HashMap
,
fs
::
File
};
use
std
::{
collections
::
HashMap
,
f32
::
consts
::
E
,
fs
::
File
};
use
csv
::
ReaderBuilder
;
...
...
@@ -104,22 +104,32 @@ pub fn from_file_path(file_path: &str) -> Result<SetPredictor, std::io::Error> {
}
pub
fn
from_file_path_and_config
(
file_path
:
&
str
,
config
:
HashMap
<
String
,
impl
Into
<
String
>>
)
->
Result
<
SetPredictor
,
std
::
io
::
Error
>
{
pub
fn
from_file_path_and_config
(
file_path
s
:
Vec
<
&
str
>
,
config
:
HashMap
<
String
,
impl
Into
<
String
>>
)
->
Result
<
SetPredictor
,
std
::
io
::
Error
>
{
let
mut
configuration
=
HashMap
::
new
();
for
(
key
,
value
)
in
config
{
configuration
.insert
(
key
,
value
.into
());
}
println!
(
"Trying to open data file at {}"
,
file_path
);
let
file
=
File
::
open
(
file_path
)
?
;
println!
(
"Reading data file..."
);
let
mut
reader
=
ReaderBuilder
::
new
()
.from_reader
(
file
);
let
mut
markov_chain
:
SetPredictor
=
SetPredictor
::
new
();
markov_chain
.configuration
=
configuration
;
for
result
in
reader
.records
()
{
let
record
=
result
?
;
if
let
Some
(
query
)
=
record
.get
(
5
)
{
markov_chain
.update
(
query
);
for
path
in
file_paths
{
println!
(
"Trying to open data file at {}"
,
path
);
match
File
::
open
(
path
)
{
Ok
(
file
)
=>
{
println!
(
"Reading data file..."
);
let
mut
reader
=
ReaderBuilder
::
new
()
.from_reader
(
file
);
for
result
in
reader
.records
()
{
let
record
=
result
?
;
if
let
Some
(
query
)
=
record
.get
(
5
)
{
markov_chain
.update
(
query
);
}
}
},
Err
(
e
)
=>
{
println!
(
"Error while reading: {}"
,
e
);
}
}
}
...
...
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