This file contains hidden or 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
    
  
  
    
  | from pypinyin import pinyin | |
| import jieba.posseg as pseg | |
| def cut(text): | |
| """demo one way to encapsulate the text with metadata, also display""" | |
| result = [] | |
| text_obj = {} | |
| for token in pseg.cut(text): | |
| word, nature = token | |
| pins = pinyin(word) | 
  
    
      This file contains hidden or 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
    
  
  
    
  | def adj(g): | |
| """ | |
| Convert a directed graph to an adjaceny matrix. | |
| >>> g = {1: {2: 3, 3: 8, 5: -4}, 2: {4: 1, 5: 7}, 3: {2: 4}, 4: {1: 2, 3: -5}, 5: {4: 6}} | |
| >>> adj(g) | |
| {1: {1: 0, 2: 3, 3: 8, 4: inf, 5: -4}, 2: {1: inf, 2: 0, 3: inf, 4: 1, 5: 7}, 3: {1: inf, 2: 4, 3: 0, 4: inf, 5: inf}, 4: {1: 2, 2: inf, 3: -5, 4: 0, 5: inf}, 5: {1: inf, 2: inf, 3: inf, 4: 6, 5: 0}} | |
| """ | |
| vertices = g.keys() | |
| dist = {} |