-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
235 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from predictor import Predictor | ||
|
||
prediction = Predictor().predict("invan/spring3-mvc-maven-json-hello-world") | ||
print(prediction) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2024 Aliaksei Bialiauski | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
import csv | ||
|
||
""" | ||
Feed. | ||
""" | ||
|
||
|
||
class Feed: | ||
def __init__(self, file): | ||
self.file = file | ||
|
||
def read(self): | ||
with open(self.file, "r") as input: | ||
reader = csv.DictReader(input) | ||
feed = [] | ||
for row in reader: | ||
name = row["full_name"] | ||
feed.append(name) | ||
return feed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2024 Aliaksei Bialiauski | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
import csv | ||
|
||
from .feed import Feed | ||
from .text_prediction import TextPrediction | ||
|
||
""" | ||
Filter pipe. | ||
""" | ||
|
||
|
||
class FilterPipe: | ||
def __init__(self, repos, output, predictor, typer): | ||
self.repos = repos | ||
self.output = output | ||
self.predictor = predictor | ||
self.typer = typer | ||
|
||
# @todo #18:60min Create integration test case for filter_pipe.py. | ||
# We should create some sort of integration test that checks filtering | ||
# together with model prediction, files creation and other things happening | ||
# in #apply(). Don't forget to remove this puzzle. | ||
def apply(self): | ||
self.typer.echo(f"Filtering {self.repos}...") | ||
feed = Feed(self.repos).read() | ||
with open("predictions.csv", "w") as predictions: | ||
writer = csv.DictWriter( | ||
predictions, | ||
fieldnames=["candidate", "prediction", "model"] | ||
) | ||
writer.writeheader() | ||
samples = [] | ||
self.typer.echo( | ||
f"Predicting... (all predictions will be saved into {predictions.name})" | ||
) | ||
for candidate in feed: | ||
prediction = self.predictor.predict(candidate) | ||
log = { | ||
"candidate": candidate, | ||
"prediction": prediction, | ||
"model": self.predictor.model() | ||
} | ||
writer.writerow(log) | ||
answer = TextPrediction(prediction).as_text() | ||
self.typer.echo(f"{candidate} classified as {answer}") | ||
if answer == "sample": | ||
samples.append(candidate) | ||
self.typer.echo(f"found {len(samples)} samples") | ||
with open(self.repos, "r") as source, open(self.output, "w") as target: | ||
reader = csv.DictReader(source) | ||
writer = csv.DictWriter(target, fieldnames=reader.fieldnames) | ||
writer.writeheader() | ||
for row in reader: | ||
identifier = row["full_name"] | ||
if identifier not in samples: | ||
writer.writerow(row) | ||
self.typer.echo(f"Filtering completed. Output saved to {self.output}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2024 Aliaksei Bialiauski | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
""" | ||
Model prediction in simple text format. | ||
""" | ||
|
||
|
||
class TextPrediction: | ||
def __init__(self, pred): | ||
self.pred = pred | ||
|
||
def as_text(self): | ||
if self.pred[0]["label"] == "POSITIVE": | ||
label = "sample" | ||
else: | ||
label = "real" | ||
return label |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2024 Aliaksei Bialiauski | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
""" | ||
Test case for TextOut. | ||
""" | ||
import unittest | ||
|
||
from objects.text_prediction import TextPrediction | ||
|
||
|
||
class TestTextOut(unittest.TestCase): | ||
|
||
def test_prints_as_real(self): | ||
prediction = [{'label': 'NEGATIVE', 'score': 1.0}] | ||
text = TextPrediction(prediction).as_text() | ||
expected = "real" | ||
self.assertEqual( | ||
text, | ||
expected, | ||
f"output '{text}' for '{prediction}' does not match with expected {expected}" | ||
) | ||
|
||
def test_prints_as_sample(self): | ||
prediction = [{'label': 'POSITIVE', 'score': 1.0}] | ||
text = TextPrediction(prediction).as_text() | ||
expected = "sample" | ||
self.assertEqual( | ||
text, | ||
expected, | ||
f"output '{text}' for '{prediction}' does not match with expected {expected}" | ||
) | ||
|
||
def test_raises_error_on_invalid_input(self): | ||
with self.assertRaises( | ||
TypeError, | ||
): | ||
TextPrediction("<invalid input>").as_text() |
1d46ae9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
10-1fb8be50
disappeared fromobjects/cli.py
), that's why I closed #18. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.1d46ae9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
19-b3973cba
disappeared fromobjects/cli.py
), that's why I closed #22. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.1d46ae9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
18-d3f80dfc
discovered inobjects/cli.py
) and submitted as #62. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.1d46ae9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
18-1f7b4ec1
discovered inobjects/filter_pipe.py
) and submitted as #63. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.