Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Thinking XML: Basic XML and RDF techniques for knowledge management

Part 2: Combining files into an RDF model, and basic RDF querying

Return to article


Listing 7: Query using regular expressions
  from Ft.Rdf import Util
from Ft.Rdf.Model import REGEX

#Returns an RDF model object, and the database instance it uses for
#persistence (in our case, it's just a memory data structure)
model, db = Util.DeserializeFromUri('issues.rdf')
db.begin()

USER_ID_BASE = 'http://users.rdfinference.org/ril/issue-tracker#'
IT_SCHEMA_BASE = 'http://xmlns.rdfinference.org/ril/issue-tracker#'

print 'Actions assigned to uogbuji:'

#Get all actions with "vote" in the body
actions = Util.GetSubjects(model, IT_SCHEMA_BASE+'body', ".*vote.*",
                           objectFlags=REGEX)

for action in actions:
    #See if this action is assigned to uogbuji
    assignee = Util.GetObject(model, action, IT_SCHEMA_BASE+'assign-to')
    body = Util.GetObject(model, action, IT_SCHEMA_BASE+'body')
    if assignee == USER_ID_BASE+'uogbuji':
        print "*", body

db.commit()



Return to article