[redland-dev] Problem: removing triple without specifying triple's object

Stefano Debenedetti ste at demaledetti.net
Tue Jul 19 16:33:58 BST 2005


Roman Bischoff ha scritto:
> 1) is it generally possible to use "None" as object node when deleting
> statements from a model?
> 
> 2) how to do it in Python?
> 
> delst = RDF.Statement(subj_node, predicate_node, None)
> del rdfmodel[delst, context_node]
> 
> ==> doesn't work.

The following code is untested but something very similar works fine for me:

def deleteSimilarStatements(model, context, subject, predicate):
	"""Delete all statements with the specified subject and predicate
	"""
	match = RDF.Statement(subject, predicate, None)
	for s in model.find_statements(match, context):
		del model[s, context]

def updateStatement(model, context, subject, predicate, object):
	"""Substitutes any existing statement with the same subject and predicate
	with the statement specified
	"""
	deleteSimilarStatements(model, context, subject, predicate)
	model.append(RDF.Statement(subject, predicate, object), context)

ciao
ste


More information about the redland-dev mailing list