Esempio n. 1
0
def shorten_url(url):
	"""Shortens a given url by collapsing it to a pair
	of identifiers denoting namespace and term, like
	``rdfs:label``."""
	#TODO: impl
	base, term = struct_uri(url)
	nspc = ns.get_ns(base)
	if nspc:
		return '{}:{}'.format(nspc.name, term)
	# TODO: if no namespace is present, shorten shomehow else
	return url
Esempio n. 2
0
def extract_ns_terms(g):
	"""Collects terms from graph rdf and assigns them
	to the namespaces they come from."""
	# TODO: filtern, so dasz einzelne namespaces bearbeitet weden
	# koennen; self.rdf in namespace klasse damit befuellen.
	for t in g:
		for u in t:
			if u:
				url, term = struct_uri(u)
				if term:
					nsp = ns.get_ns(url)
					if nsp:
						#print '\n\nextract namespace term from rdf data:',
						#print '{}..{}'.format(url[:10],url[-10:]), nsp.name, term
						dest = [nsp.classes, nsp.properties][int(term.islower())]
						if not term in dest:
							dest.append(term)