Beispiel #1
0
def expand_term(token):
	"""Un-shorten url."""
	nn, term = token.rsplit(':',1)
	nsp = ns.get(nn)
	if nsp:
		return rdflib.URIRef('{}{}'.format(nsp.url, term))
	return rdflib.URIRef(token)
Beispiel #2
0
	def _construct_namespaces(self):
		namespaces.init_core(self)
		
		count = namespaces.count(self)
		for index in range(count):
			namespace = namespaces.get(self,index)
			self._namespace_list.append(namespace.name)
			self._namespaces[namespace.name] = namespace
Beispiel #3
0
def find_term(term, nsp=None, g=None):
	"""Shows triple containing given term."""
	if not g:
		g = globals().get('current_graph')
	if g:
		res = []
		if nsp != None and nsp in ns.get_names():
			res.extend(['Search for occurences of resouce id {}:{} in {}'.format(
				ns.get(nsp).name, term, graph_name(g))])
			prefix = ns.get(nsp).url
			nsp = None
		else:
			prefix = '\S*'
		pttn = '{}[#/]?{}'.format(prefix, term)
		query = re.compile(pttn)
		#print query.pattern
		# substitution string for query matches
		if nsp:
			if term:
				subst = u'*{}:{}*'.format(nsp,term)
			else:
				subst = u'*{}*'.format(nsp)
		else:
			subst = u'*:{}*'.format(term)
		# serach through triple list
		for trp in ls_rdf(g=g):
			stm = u'{} {} {}'.format(*trp)
			#if stm.find('Glenys Stacey') > 0:
				#print stm
				#res.append(stm)
			# occurence of desired ref entity?
			occ = query.findall(stm)
			if len(occ)>0:
				for o in occ:
					stm = re.sub(pttn, subst, stm)
				res.append(stm)
		return res