두 개의 텍스트 파일이 있고 하나의 파일에는 Neo4j 스크립트가 들어 있고 다른 파일에는 일부 문서 ID 및 색인이있는 국가 및 도시 목록이 들어 있습니다. 아래에 주어진 :파이썬에서 조합하면서 텍스트 문서 분할하기
사이퍼 파일 :
MATCH (t:Country {name:'%a'}),(o:City {name:'%b'})
WITH point({ longitude: toFloat(t.longitude), latitude: toFloat(t.latitude) }) AS copoint, point({ longitude: toFloat(o.longitude), latitude: toFloat(o.latitude) }) AS cipoint
RETURN distance(copoint, cipoint)
텍스트 파일 :
5 <DOCID>GH950102-000000<DOCID>/O
114 Cardiff/LOCATION
321 United States'/LOCATION
898 Alps/LOCATION
1029 Dresden/LOCATION
1150 Scotland/LOCATION
1162 Gasforth/LOCATION
1258 Arabia/LOCATION
1261 Hejaz/LOCATION
1265 Aleppo/LOCATION
1267 Northern Syria/LOCATION
1269 Aqaba/LOCATION
1271 Jordan./LOCATION
1543 London/LOCATION
1556 London/LOCATION
1609 London/LOCATION
2040 <DOCID>GH950102-000001<DOCID>/O
2317 America/LOCATION
3096 New York./LOCATION
3131 Great Britain/LOCATION
3147 <DOCID>GH950102-000002<DOCID>/O
3184 Edinburgh/LOCATION
<DOCID>GH950102-000003<DOCID>/O
3243 Australia/LOCATION
3360 England/LOCATION
3414 India/LOCATION
3474 Melbourne/LOCATION
3497 England/LOCATION
내 질문은이 문서를 분할 할 때마다 DOCID
나타납니다 각 사이의 모든 위치 이름 사이의 조합을 촬영하는 방법입니다 DOCID
. Index Number
을 제거하고 Cypher 스크립트에서 위치 이름을 복사하는 동안 /location
도 제거해야합니다.
이 코드로 시도했지만 도움이되지 않았습니다.
from itertools import combinations
with open ("results.txt") as f:
for line in f:
for "DOCID" in line.split():
cities = (city.strip() for city in f.readlines())
with open ("cypher.txt") as g:
cypher_query =g.readlines()
with open ("resultfile.txt","w") as f:
for city1,city2 in combinations (cities,2):
f.writelines(line.replace("%a",city1).replace("%b",city2) for line in cypher_query)
f.write("\n")
더 DOCID 문자열을 존재하지 않는, 당신은 DOCID 무엇을 의미 명확히하십시오. – voiDnyx
나는 편집을 시도했으나 일어나지 않고 누군가가 이미 편집을 제안했지만 승인 할 수 없으므로 승인을 기다리고 있으므로 DOCID가 표시 될 수 있습니다 – Moizzy