-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More flexible handling of encoding error #10
Open
leojoubert
wants to merge
4
commits into
halfak:master
Choose a base branch
from
leojoubert:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,20 @@ | ||
def apply_get_a(operations_diff_file): | ||
length_a = max([operation["a2"] for operation in operations_diff_file]) | ||
a = [''] * length_a | ||
|
||
for operation in operations_diff_file: | ||
|
||
if operation["name"] == "equal" or operation["name"] == "delete": | ||
#print("Equal: {0}".format(str(a_tokens[operation.a1:operation.a2]))) | ||
if "tokens" in operation.keys(): | ||
a[operation["a1"]:operation["a2"]] = operation["tokens"] | ||
|
||
elif operation["name"] == "insert": | ||
#print("Insert: {0}".format(str(b_tokens[operation.b1:operation.b2]))) | ||
pass | ||
|
||
else: | ||
raise TypeError("Unexpected operation type " + \ | ||
"{0}".format(type(operation))) | ||
|
||
return ' '.join(a) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why join everything with a space? |
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,21 @@ | ||
def apply_get_b(operations_diff_file): | ||
|
||
length_b = max([operation["b2"] for operation in operations_diff_file]) | ||
b = [''] * length_b | ||
|
||
for operation in operations_diff_file: | ||
|
||
if operation["name"] == "equal" or operation["name"] == "insert": | ||
#print("Equal: {0}".format(str(a_tokens[operation.a1:operation.a2]))) | ||
if "tokens" in operation.keys(): | ||
b[operation["b1"]:operation["b2"]] = operation["tokens"] | ||
|
||
elif operation["name"] == "delete": | ||
#print("Insert: {0}".format(str(b_tokens[operation.b1:operation.b2]))) | ||
pass | ||
|
||
else: | ||
raise TypeError("Unexpected operation type " + \ | ||
"{0}".format(type(operation))) | ||
|
||
return ' '.join(b) |
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 |
---|---|---|
|
@@ -94,7 +94,7 @@ class MatchableSegment(Segment): | |
|
||
def initialize(self, *args, **kwargs): | ||
super().initialize(*args, **kwargs) | ||
self.sha1 = hashlib.sha1(bytes(str(self), 'utf-8')) | ||
self.sha1 = hashlib.sha1(bytes(str(self), 'utf-8', errors = "replace")) | ||
self.match = None | ||
|
||
def __eq__(self, other): | ||
|
@@ -117,7 +117,7 @@ def __setstate__(self, args): self.initialize(*args) | |
|
||
def append(self, subsegment): | ||
super().append(subsegment) | ||
self.sha1.update(bytes(str(subsegment), 'utf-8')) | ||
self.sha1.update(bytes(str(subsegment), 'utf-8', errors = "replace")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 this is a good idea. |
||
|
||
def extend(self, subsegments): | ||
for subsegment in subsegments: | ||
|
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,17 @@ | ||
# Faire l'exemple suivant : | ||
|
||
- un chien est un sale animal | ||
- Iris est un sale animal | ||
- Iris est un sale chat | ||
|
||
# incompréhension | ||
|
||
- fonctionnement de la fonction apply : pourquoi yield ? | ||
|
||
# Différences dans les operations | ||
|
||
- dans les diff, il y a les tokens qui permettent de reconstruire le fichier, pas dans le apply **voilà pouruqoi le package original ne permet pas cette fonction** | ||
|
||
# Manuel d'utilisation | ||
|
||
- s'assurer que l'on a bien le même tokenizer de l'un à l'autre |
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,33 @@ | ||
from deltas import segment_matcher, text_split | ||
from deltas import apply_get_a, apply_get_b | ||
from deltas import Operation, Insert, Delete, Equal | ||
|
||
import deltas | ||
from pprint import pprint | ||
|
||
a = text_split.tokenize("This is some text. This is some other text.") | ||
b = text_split.tokenize("This is some other text. This is some text.") | ||
operations = segment_matcher.diff(a, b) | ||
|
||
operations_format = [] | ||
for op in operations: | ||
tmp = { | ||
'name': op.name, | ||
'a1': op.a1, | ||
'b1': op.b1, | ||
'a2': op.a2, | ||
'b2': op.b2, | ||
'tokens' : [str(token) for token in op.relevant_tokens(a,b)] | ||
} | ||
operations_format.append(tmp) | ||
|
||
print(apply_get_a(operations_format)) | ||
print(apply_get_b(operations_format)) | ||
|
||
operations_new = [] | ||
for op in operations_format: | ||
tmp = Operation(name = op["name"], a1 = op["a1"], a2 = op["a2"], b1 = op["b1"], b2 = op["b2"]) | ||
operations_new.append(tmp) | ||
|
||
print(operations) | ||
print(operations_new) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What's the goal of this method? Maybe some docs or a test would be welcome.