当前位置: 首页>>代码示例>>Python>>正文


Python Graph.addEdge方法代码示例

本文整理汇总了Python中py2neo.Graph.addEdge方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.addEdge方法的具体用法?Python Graph.addEdge怎么用?Python Graph.addEdge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在py2neo.Graph的用法示例。


在下文中一共展示了Graph.addEdge方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process_courses

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import addEdge [as 别名]
def process_courses():
	# to match stuff like this ZOO 5748C COM-BSBS 5(3,2)
	regex = re.compile('(\w{3}) ([0-9]{4}[A-Z]?) (.*(?:\s.*)?) (\d\(\d,\d\))\n?')

	count = 0
	id = 0
	g = Graph()
	with open('../course_list.txt', 'r') as f:
		line = f.readline()
		# print line
		while(line is not ''):
			count += 1
			# print count
			properties= {}
			match = regex.match(line)
			if match:
				try:
					(prefix, number, college, credits) = match.group(1,2,3,4)
					properties.update({
						'prefix': prefix,
						'number': number,
						'college': college,
						'credits': credits
						})

					if (prefix+number) not in courseNodes:
						courseNodes[prefix+number] = {
							'id': id,
							'node': Node("Course", name=(prefix+number)),
							'name': prefix+number
						}

						id += 1
				except ValueError:
					print 'error line', line
					print match.group()
					raise Error

				body = ''
				line = f.readline()
				while(not regex.match(line) and line is not ''):
					count +=1
					# print count
					# print line
					if not regex.match(line):
						body += line
					line = f.readline()

				# split into name, prereqs, and description
				res = re.split(':(?:\s)?|\.\s(?=[A-Z])', body)
				if 'PR' in body:
					[name, _, _prereqs] = res[0:3]
					properties['body'] = res[3:]
				else:
					[name, body] = res[0:2]
					_prereqs = 'none'
					properties['body'] = body

				_prereqs = _prereqs.replace('\n', ' ')
				# regex match the course prefx and number
				prereq_matches =  re.compile('(\w{3})\s(?:\s)?([0-9]{4}[A-Z]?)').findall(_prereqs)
				prereqs = map(lambda t: ''.join(list(t)), prereq_matches)

				properties['prereqs'] = prereqs
				properties['name'] = name.replace('\n', ' ')

				properties['id'] = prefix+number

				courseNodes[prefix+number]['name'] = properties['name']

				course = Course(properties)
				courses.append(course)
				g.addNode(course)
				for prq in prereqs:
					g.addEdge([course.id, prq])

				if college == "COS-MATH":
					courseNodes[prefix+number]['group'] = 16
					math_courses.append(Course(properties))
				if "ECS" in college:
					courseNodes[prefix+number]['group'] = 2

			else:
				line = f.readline()

		return g
开发者ID:birdman7260,项目名称:skilltree,代码行数:88,代码来源:process_courses.py


注:本文中的py2neo.Graph.addEdge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。