Giter Club home page Giter Club logo

Comments (2)

Janchorizo avatar Janchorizo commented on June 9, 2024

I have tried replicating this issue and the following is what I found:

After loading the adhered document and annotating it, there are some cases in which the
annotation failed on me.

image

Having those annotations, and selecting the fourth word in the paragraph (Coppaun), I
the server fails at creating the annotation. The following screenshot shows the retrieved document
at app load, the message sent to the server, and the slice of the original document using
the sent positions:

image

The server-side code fails in the _add_tag method.

def __add_tag(self, annotated_fragment, tag, uncertainty=False, reference=False):
new_annotated_fragment = ''
annotation_ids = []
while len(annotated_fragment) > 0:
# handle xml tag
if re.search(r'^\s*?<[^<>]*?>', annotated_fragment):
match = re.search(r'^\s*?<[^<>]*?>', annotated_fragment)
tag_to_move = match.group()
end_tag = '</' + tag
empty_tag = '<' + tag + '/'
if tag in tag_to_move and end_tag not in tag_to_move and empty_tag not in tag_to_move:
match = re.search(r'<[^>\s]+', tag_to_move)
tag_begin = match.group()
if uncertainty:
if 'xml:id="' not in tag_to_move:
id = f"{tag}_{self.__file.name}-{self.__tag_xml_id_number}"
attribute = f' xml:id="{id}"'
annotation_ids.append('#' + id)
new_tag_to_move = tag_to_move[:len(tag_begin)] + attribute + tag_to_move[len(tag_begin):]
self.__tag_xml_id_number += 1
else:
match = re.search(r'xml:id=".*?"', tag_to_move)
existing_id = match.group()
existing_id = existing_id.replace('xml:id="', '')
existing_id = existing_id.replace('"', '')
annotation_ids.append('#' + existing_id)
new_tag_to_move = tag_to_move
new_annotated_fragment += new_tag_to_move
elif reference:
if 'ref="' not in tag_to_move:
id = self.__get_id_of_list_object_to_reference()
attribute = f' ref="#{id}"'
annotation_ids.append('#' + id)
new_tag_to_move = tag_to_move[:len(tag_begin)] + attribute + tag_to_move[len(tag_begin):]
else:
match = re.search(r'ref=".*?"', tag_to_move)
existing_reference = match.group()
id = self.__get_id_of_list_object_to_reference()
if id in existing_reference:
raise NotModified(f"Reference to element with xml:id: {id} already exist.")
updated_reference = f'{existing_reference[:-1]} #{id}"'
annotation_ids.append('#' + id)
new_tag_to_move = tag_to_move.replace(existing_reference, updated_reference)
new_annotated_fragment += new_tag_to_move
else:
new_annotated_fragment += tag_to_move
annotated_fragment = annotated_fragment[len(tag_to_move):]
# handle text
else:
match = re.search(r'^\s*[^<>]+', annotated_fragment)
text_to_move = match.group()
if tag in self.__tags:
new_annotated_fragment += text_to_move
annotated_fragment = annotated_fragment[len(text_to_move):]
else:
attribute = ""
if uncertainty:
id = f"{tag}_{self.__file.name}-{self.__tag_xml_id_number}"
attribute = f' xml:id="{id}"'
annotation_ids.append('#' + id)
elif reference:
id = self.__get_id_of_list_object_to_reference()
attribute = f' ref="#{id}"'
annotation_ids.append('#' + id)
tag_open = f'<{tag}{attribute}>'
tag_close = f'</{tag}>'
new_annotated_fragment += tag_open + text_to_move + tag_close
annotated_fragment = annotated_fragment[len(text_to_move):]
if uncertainty:
self.__tag_xml_id_number += 1
return new_annotated_fragment, annotation_ids

The annotated_fragment argument is
set to a different value than what is obtained in the front-end: </date> Coppaun<gap/>

from collaborative-platform.

bug-rancher avatar bug-rancher commented on June 9, 2024

I replicated your bug. The root of this bug is this same as in first message in this issue - wrong positions in request. The difference is that positions pointing to fragment with part of the tag on the end instead on the beginning ('Coppaun<' instead 'objectName ref="#object_recipe_0_xml-1">Guetten' as in first post).

I added a validation to check for that exceptions, and now, if this exception will occur, backend will return a proper message with included fragment of xml based on positions from request. This will stop WebSockets from disconnecting in this cases and I hope this will help you to figure out why positions in request sometimes are wrong.

Zrzut ekranu z 2020-01-28 13-45-44

from collaborative-platform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.