내가 파일의 file.Each 값에서 값을 복용하고이 목적을 index.For 반전 만드는 중이라서이 형태 :파이썬 멀티 레벨 기본 딕셔너리
DOCUMENT_ID '\ t'term_Id'\ t'pos_1 ' \ t'pos_2 ... '\ t'pos_n
이
term_Id과 같아야합니다 representation.I 반전 인덱스로 변환하고자하는 기대 지수는'\의 t ' "DOC_ID : POS1, POS2 ... posn ""doc_Id : pos1, pos2 ... posn "
그 목적을 위해 목록 유형의 기본 사전을 사용하고 있습니다.이게 내 재미입니다. ction :
nestedDict = defaultdict(lambda:defaultdict(list))
def getInfo(line):
global nestedDict
tokens = re.split(r'\t+',line)
docInfo = int(tokens[0]) #Set document Id
termId = int(tokens[1]) #Set Term Id
currentPosition = int(tokens[2])
nestedDict[str(termId)][str(docInfo)] = str(currentPosition)
if len(tokens) > 3 :
for i in range(3,len(tokens)):
position = int(tokens[i])-currentPosition
currentPosition = currentPosition + position
nestedDict[str(termId)][str(docInfo)].append(currentPosition)
내게 오류가 발생했습니다. Str에 메서드가 없습니다. append. 저는 python에 처음 왔습니다. 아무 도움이 높게 평가 될 것입니다.
'global'은 아무 것도하지 않습니다; 당신은'nestedDict'라는 이름에 할당하지 않습니다. –
루프의 처음 두 줄은'currentPosition = int (tokens [i])'를 작성하는 정말 복잡한 방법입니다. –