test.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #
  2. # Metrix++, Copyright 2009-2019, Metrix++ Project
  3. # Link: https://github.com/metrixplusplus/metrixplusplus
  4. #
  5. # This file is a part of Metrix++ Tool.
  6. #
  7. import mpp.api
  8. import logging
  9. # used for testing and development purposes
  10. class Plugin(mpp.api.Plugin, mpp.api.Child):
  11. def initialize(self):
  12. return
  13. # do not trigger version property set, it is a module for testing purposes
  14. self.subscribe_by_parents_interface(mpp.api.ICode)
  15. def callback(self, parent, data, is_updated):
  16. text = data.get_content()
  17. text_comb = ""
  18. for region in data.iterate_regions():
  19. logging.warn(region.get_name() + " " + str(region.get_cursor()))
  20. for marker in data.iterate_markers(region_id=region.get_id(),
  21. filter_group = mpp.api.Marker.T.ANY,
  22. exclude_children = True):
  23. logging.warn("\tMarker: " + mpp.api.Marker.T().to_str(marker.get_type()) +
  24. " " + str(marker.get_offset_begin()) + " " + str(marker.get_offset_end()) +
  25. " >>>" + text[marker.get_offset_begin():marker.get_offset_end()] + "<<<")
  26. text_comb += text[marker.get_offset_begin():marker.get_offset_end()]
  27. print "LENGTH:", len(text), len(text_comb)
  28. text_comb = ""
  29. for marker in data.iterate_markers(region_id=1,
  30. filter_group = mpp.api.Marker.T.ANY,
  31. exclude_children = False):
  32. logging.warn("\tMarker: " + mpp.api.Marker.T().to_str(marker.get_type()) +
  33. " " + str(marker.get_offset_begin()) + " " + str(marker.get_offset_end()) +
  34. " >>>" + text[marker.get_offset_begin():marker.get_offset_end()] + "<<<")
  35. text_comb += text[marker.get_offset_begin():marker.get_offset_end()]
  36. print "LENGTH:", len(text), len(text_comb)
  37. text_comb = ""
  38. for region in data.iterate_regions():
  39. logging.warn(region.get_name() + " " + str(region.get_cursor()))
  40. for marker in data.iterate_markers(region_id=region.get_id(),
  41. filter_group = mpp.api.Marker.T.ANY,
  42. exclude_children = True,
  43. merge = True):
  44. logging.warn("\tMarker: merged" +
  45. " " + str(marker.get_offset_begin()) + " " + str(marker.get_offset_end()) +
  46. " >>>" + text[marker.get_offset_begin():marker.get_offset_end()] + "<<<")
  47. text_comb += text[marker.get_offset_begin():marker.get_offset_end()]
  48. print "LENGTH:", len(text), len(text_comb)