示例#1
0
  def testJoinOneChild(self):
    """Tests that we can join some children but not all."""

    #   'c'            ----'c'
    #   /            /     /
    # 'a'          'a'    /
    #   \            \   /
    #   'd'          'd'/
    #          =>      /
    #   'c'           /
    #   /            /
    # 'b'          'b'
    #   \            \
    #   'e'          'e'

    node6 = ( 'e', [ None ] )
    node5 = ( 'c', [ None ] )
    node4 = ( 'b', [ node5, node6 ] )
    node3 = ( 'd', [ None ] )
    node2 = ( 'c', [ None ] )
    node1 = ( 'a', [ node2, node3 ] )
    source1 = [ node1, node4 ]
    source2 = make_dafsa.join_suffixes(source1)

    # Both versions should expand to the same content.
    self.assertEqual(source1, source2)
    # But the new version should have just one 'c'.
    self.assertIs(source2[0][1][0], source2[1][1][0])
示例#2
0
  def testMakeRecursiveTrie(self):
    """Tests recursive suffix join."""

    # 'a' -> 'e' -> 'g'     'a'
    #                         \
    #                         'e'
    #                         / \
    # 'b' -> 'e' -> 'g'     'b'  \
    #                             \
    #                   =>        'g'
    #                             /
    # 'c' -> 'f' -> 'g'     'c'  /
    #                         \ /
    #                         'f'
    #                         /
    # 'd' -> 'f' -> 'g'     'd'

    node7 = ( 'g', [ None ] )
    node6 = ( 'f', [ node7 ] )
    node5 = ( 'e', [ node7 ] )
    node4 = ( 'd', [ node6 ] )
    node3 = ( 'c', [ node6 ] )
    node2 = ( 'b', [ node5 ] )
    node1 = ( 'a', [ node5 ] )
    source1 = [ node1, node2, node3, node4 ]
    source2 = make_dafsa.join_suffixes(source1)

    # Both versions should expand to the same content.
    self.assertEqual(source1, source2)
    # But the new version should have just one 'e'.
    self.assertIs(source2[0][1][0], source2[1][1][0])
    # And one 'f'.
    self.assertIs(source2[2][1][0], source2[3][1][0])
    # And one 'g'.
    self.assertIs(source2[0][1][0][1][0], source2[2][1][0][1][0])
示例#3
0
  def testJoinOneChild(self):
    """Tests that we can join some children but not all."""

    #   'c'            ----'c'
    #   /            /     /
    # 'a'          'a'    /
    #   \            \   /
    #   'd'          'd'/
    #          =>      /
    #   'c'           /
    #   /            /
    # 'b'          'b'
    #   \            \
    #   'e'          'e'

    node6 = ( 'e', [ None ] )
    node5 = ( 'c', [ None ] )
    node4 = ( 'b', [ node5, node6 ] )
    node3 = ( 'd', [ None ] )
    node2 = ( 'c', [ None ] )
    node1 = ( 'a', [ node2, node3 ] )
    source1 = [ node1, node4 ]
    source2 = make_dafsa.join_suffixes(source1)

    # Both versions should expand to the same content.
    self.assertEqual(source1, source2)
    # But the new version should have just one 'c'.
    self.assertIs(source2[0][1][0], source2[1][1][0])
示例#4
0
  def testMakeRecursiveTrie(self):
    """Tests recursive suffix join."""

    # 'a' -> 'e' -> 'g'     'a'
    #                         \
    #                         'e'
    #                         / \
    # 'b' -> 'e' -> 'g'     'b'  \
    #                             \
    #                   =>        'g'
    #                             /
    # 'c' -> 'f' -> 'g'     'c'  /
    #                         \ /
    #                         'f'
    #                         /
    # 'd' -> 'f' -> 'g'     'd'

    node7 = ( 'g', [ None ] )
    node6 = ( 'f', [ node7 ] )
    node5 = ( 'e', [ node7 ] )
    node4 = ( 'd', [ node6 ] )
    node3 = ( 'c', [ node6 ] )
    node2 = ( 'b', [ node5 ] )
    node1 = ( 'a', [ node5 ] )
    source1 = [ node1, node2, node3, node4 ]
    source2 = make_dafsa.join_suffixes(source1)

    # Both versions should expand to the same content.
    self.assertEqual(source1, source2)
    # But the new version should have just one 'e'.
    self.assertIs(source2[0][1][0], source2[1][1][0])
    # And one 'f'.
    self.assertIs(source2[2][1][0], source2[3][1][0])
    # And one 'g'.
    self.assertIs(source2[0][1][0][1][0], source2[2][1][0][1][0])
示例#5
0
  def testSingleLabel(self):
    """Tests a single label passes unchanged."""

    # 'a'  =>  'a'

    node1 = ( 'a', [ None ] )
    source = [ node1 ]
    self.assertEqual(make_dafsa.join_suffixes(source), source)
示例#6
0
  def testSingleLabel(self):
    """Tests a single label passes unchanged."""

    # 'a'  =>  'a'

    node1 = ( 'a', [ None ] )
    source = [ node1 ]
    self.assertEqual(make_dafsa.join_suffixes(source), source)
示例#7
0
  def testInnerTerminator(self):
    """Tests a sequence with an inner terminator passes unchanged."""

    # 'a' -> 'b'    'a' -> 'b'
    #   \       =>    \
    #  {sink}        {sink}

    node2 = ( 'b', [ None ] )
    node1 = ( 'a', [ node2, None ] )
    source = [ node1 ]
    self.assertEqual(make_dafsa.join_suffixes(source), source)
示例#8
0
  def testInnerTerminator(self):
    """Tests a sequence with an inner terminator passes unchanged."""

    # 'a' -> 'b'    'a' -> 'b'
    #   \       =>    \
    #  {sink}        {sink}

    node2 = ( 'b', [ None ] )
    node1 = ( 'a', [ node2, None ] )
    source = [ node1 ]
    self.assertEqual(make_dafsa.join_suffixes(source), source)
示例#9
0
  def testDistinctTrie(self):
    """Tests a trie formed DAFSA with distinct labels passes unchanged."""

    #   'b'       'b'
    #   /         /
    # 'a'   =>  'a'
    #   \         \
    #   'c'       'c'

    node3 = ( 'c', [ None ] )
    node2 = ( 'b', [ None ] )
    node1 = ( 'a', [ node2, node3 ] )
    source = [ node1 ]
    self.assertEqual(make_dafsa.join_suffixes(source), source)
示例#10
0
  def testDistinctTrie(self):
    """Tests a trie formed DAFSA with distinct labels passes unchanged."""

    #   'b'       'b'
    #   /         /
    # 'a'   =>  'a'
    #   \         \
    #   'c'       'c'

    node3 = ( 'c', [ None ] )
    node2 = ( 'b', [ None ] )
    node1 = ( 'a', [ node2, node3 ] )
    source = [ node1 ]
    self.assertEqual(make_dafsa.join_suffixes(source), source)
示例#11
0
  def testJoinTails(self):
    """Tests tails can be joined."""

    # 'a' -> 'c'      'a'
    #                   \
    #             =>    'c'
    #                   /
    # 'b' -> 'c'      'b'

    node4 = ( 'c', [ None ] )
    node3 = ( 'b', [ node4 ] )
    node2 = ( 'c', [ None ] )
    node1 = ( 'a', [ node2 ] )
    source1 = [ node1, node3 ]
    source2 = make_dafsa.join_suffixes(source1)

    # Both versions should expand to the same content.
    self.assertEqual(source1, source2)
    # But the new version should have just one tail.
    self.assertIs(source2[0][1][0], source2[1][1][0])
示例#12
0
  def testJoinTails(self):
    """Tests tails can be joined."""

    # 'a' -> 'c'      'a'
    #                   \
    #             =>    'c'
    #                   /
    # 'b' -> 'c'      'b'

    node4 = ( 'c', [ None ] )
    node3 = ( 'b', [ node4 ] )
    node2 = ( 'c', [ None ] )
    node1 = ( 'a', [ node2 ] )
    source1 = [ node1, node3 ]
    source2 = make_dafsa.join_suffixes(source1)

    # Both versions should expand to the same content.
    self.assertEqual(source1, source2)
    # But the new version should have just one tail.
    self.assertIs(source2[0][1][0], source2[1][1][0])
示例#13
0
  def testMakeDiamond(self):
    """Test we can join suffixes of a trie."""

    #   'b' -> 'd'        'b'
    #   /                 / \
    # 'a'           =>  'a' 'd'
    #   \                 \ /
    #   'c' -> 'd'        'c'

    node5 = ( 'd', [ None ] )
    node4 = ( 'c', [ node5 ] )
    node3 = ( 'd', [ None ] )
    node2 = ( 'b', [ node3 ] )
    node1 = ( 'a', [ node2, node4 ] )
    source1 = [ node1 ]
    source2 = make_dafsa.join_suffixes(source1)

    # Both versions should expand to the same content.
    self.assertEqual(source1, source2)
    # But the new version should have just one 'd'.
    self.assertIs(source2[0][1][0][1][0], source2[0][1][1][1][0])
示例#14
0
  def testMakeDiamond(self):
    """Test we can join suffixes of a trie."""

    #   'b' -> 'd'        'b'
    #   /                 / \
    # 'a'           =>  'a' 'd'
    #   \                 \ /
    #   'c' -> 'd'        'c'

    node5 = ( 'd', [ None ] )
    node4 = ( 'c', [ node5 ] )
    node3 = ( 'd', [ None ] )
    node2 = ( 'b', [ node3 ] )
    node1 = ( 'a', [ node2, node4 ] )
    source1 = [ node1 ]
    source2 = make_dafsa.join_suffixes(source1)

    # Both versions should expand to the same content.
    self.assertEqual(source1, source2)
    # But the new version should have just one 'd'.
    self.assertIs(source2[0][1][0][1][0], source2[0][1][1][1][0])
示例#15
0
  def testJoinTwoHeads(self):
    """Tests two heads can be joined even if there is something else between."""

    # 'a'       ------'a'
    #                 /
    # 'b'  =>  'b'   /
    #               /
    # 'a'       ---
    #
    # The picture above should shows that the new version should have just one
    # instance of the node with label 'a'.

    node3 = ( 'a', [ None ] )
    node2 = ( 'b', [ None ] )
    node1 = ( 'a', [ None ] )
    source1 = [ node1, node2, node3 ]
    source2 = make_dafsa.join_suffixes(source1)

    # Both versions should expand to the same content.
    self.assertEqual(source1, source2)
    # But the new version should have just one instance of 'a'.
    self.assertIs(source2[0], source2[2])
示例#16
0
  def testJoinTwoHeads(self):
    """Tests two heads can be joined even if there is something else between."""

    # 'a'       ------'a'
    #                 /
    # 'b'  =>  'b'   /
    #               /
    # 'a'       ---
    #
    # The picture above should shows that the new version should have just one
    # instance of the node with label 'a'.

    node3 = ( 'a', [ None ] )
    node2 = ( 'b', [ None ] )
    node1 = ( 'a', [ None ] )
    source1 = [ node1, node2, node3 ]
    source2 = make_dafsa.join_suffixes(source1)

    # Both versions should expand to the same content.
    self.assertEqual(source1, source2)
    # But the new version should have just one instance of 'a'.
    self.assertIs(source2[0], source2[2])