test.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #
  2. # Metrix++, Copyright 2009-2013, Metrix++ Project
  3. # Link: http://metrixplusplus.sourceforge.net
  4. #
  5. # This file is a part of Metrix++ Tool.
  6. #
  7. # Metrix++ is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, version 3 of the License.
  10. #
  11. # Metrix++ is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Metrix++. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import mpp.api
  20. import logging
  21. # used for testing and development purposes
  22. class Plugin(mpp.api.Plugin, mpp.api.Child):
  23. def initialize(self):
  24. return
  25. # do not trigger version property set, it is a module for testing purposes
  26. self.subscribe_by_parents_interface(mpp.api.ICode)
  27. def callback(self, parent, data, is_updated):
  28. text = data.get_content()
  29. text_comb = ""
  30. for region in data.iterate_regions():
  31. logging.warn(region.get_name() + " " + str(region.get_cursor()))
  32. for marker in data.iterate_markers(region_id=region.get_id(),
  33. filter_group = mpp.api.Marker.T.ANY,
  34. exclude_children = True):
  35. logging.warn("\tMarker: " + mpp.api.Marker.T().to_str(marker.get_type()) +
  36. " " + str(marker.get_offset_begin()) + " " + str(marker.get_offset_end()) +
  37. " >>>" + text[marker.get_offset_begin():marker.get_offset_end()] + "<<<")
  38. text_comb += text[marker.get_offset_begin():marker.get_offset_end()]
  39. print "LENGTH:", len(text), len(text_comb)
  40. text_comb = ""
  41. for marker in data.iterate_markers(region_id=1,
  42. filter_group = mpp.api.Marker.T.ANY,
  43. exclude_children = False):
  44. logging.warn("\tMarker: " + mpp.api.Marker.T().to_str(marker.get_type()) +
  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)
  49. text_comb = ""
  50. for region in data.iterate_regions():
  51. logging.warn(region.get_name() + " " + str(region.get_cursor()))
  52. for marker in data.iterate_markers(region_id=region.get_id(),
  53. filter_group = mpp.api.Marker.T.ANY,
  54. exclude_children = True,
  55. merge = True):
  56. logging.warn("\tMarker: merged" +
  57. " " + str(marker.get_offset_begin()) + " " + str(marker.get_offset_end()) +
  58. " >>>" + text[marker.get_offset_begin():marker.get_offset_end()] + "<<<")
  59. text_comb += text[marker.get_offset_begin():marker.get_offset_end()]
  60. print "LENGTH:", len(text), len(text_comb)