Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 467793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:37:03+00:00 2026-05-12T23:37:03+00:00

I am having trouble finding a clear, sensible example of usage of context with

  • 0

I am having trouble finding a clear, sensible example of usage of context with rdflib.
ConjunctiveGraph does not accept contexts, and Graph is deprecated. How am I supposed to create and operate on different contexts within the same global ConjunctiveGraph ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T23:37:04+00:00Added an answer on May 12, 2026 at 11:37 pm

    Yes. This is the code

    import rdflib
    from rdflib.Graph import Graph
    
    conj=rdflib.ConjunctiveGraph()
    
    NS=rdflib.Namespace("http://example.com/#")
    NS_CTX=rdflib.Namespace("http://example.com/context/#")
    
    alice=NS.alice
    bob=NS.bob
    charlie=NS.charlie
    
    pizza=NS.pizza
    meat=NS.meat
    chocolate=NS.chocolate
    
    loves=NS.loves
    hates=NS.hates
    likes=NS.likes
    dislikes=NS.dislikes
    
    love_ctx=Graph(conj.store, NS_CTX.love)
    food_ctx=Graph(conj.store, NS_CTX.food)
    
    love_ctx.add( (alice, loves, bob) )
    love_ctx.add( (alice, loves, charlie) )
    love_ctx.add( (bob, hates, charlie) )
    love_ctx.add( (charlie, loves, bob) )
    
    food_ctx.add( (alice, likes, chocolate) )
    food_ctx.add( (alice, likes, meat) )
    food_ctx.add( (alice, dislikes, pizza) )
    
    print "Full context"
    for t in conj:
        print t
    
    print ""
    print "Contexts"
    for c in conj.contexts():
        print c
    
    print "love context"
    for t in love_ctx:
        print t
    
    print "food context"
    for t in food_ctx:
        print t
    

    And this is the output

    Full context
    (rdflib.URIRef('http://example.com/#bob'), rdflib.URIRef('http://example.com/#hates'), rdflib.URIRef('http://example.com/#charlie'))
    (rdflib.URIRef('http://example.com/#alice'), rdflib.URIRef('http://example.com/#likes'), rdflib.URIRef('http://example.com/#chocolate'))
    (rdflib.URIRef('http://example.com/#alice'), rdflib.URIRef('http://example.com/#likes'), rdflib.URIRef('http://example.com/#meat'))
    (rdflib.URIRef('http://example.com/#alice'), rdflib.URIRef('http://example.com/#dislikes'), rdflib.URIRef('http://example.com/#pizza'))
    (rdflib.URIRef('http://example.com/#alice'), rdflib.URIRef('http://example.com/#loves'), rdflib.URIRef('http://example.com/#bob'))
    (rdflib.URIRef('http://example.com/#alice'), rdflib.URIRef('http://example.com/#loves'), rdflib.URIRef('http://example.com/#charlie'))
    (rdflib.URIRef('http://example.com/#charlie'), rdflib.URIRef('http://example.com/#loves'), rdflib.URIRef('http://example.com/#bob'))
    
    Contexts
    <http://example.com/context/#food> a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory'].
    <http://example.com/context/#love> a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory'].
    love context
    (rdflib.URIRef('http://example.com/#bob'), rdflib.URIRef('http://example.com/#hates'), rdflib.URIRef('http://example.com/#charlie'))
    (rdflib.URIRef('http://example.com/#alice'), rdflib.URIRef('http://example.com/#loves'), rdflib.URIRef('http://example.com/#bob'))
    (rdflib.URIRef('http://example.com/#alice'), rdflib.URIRef('http://example.com/#loves'), rdflib.URIRef('http://example.com/#charlie'))
    (rdflib.URIRef('http://example.com/#charlie'), rdflib.URIRef('http://example.com/#loves'), rdflib.URIRef('http://example.com/#bob'))
    food context
    (rdflib.URIRef('http://example.com/#alice'), rdflib.URIRef('http://example.com/#likes'), rdflib.URIRef('http://example.com/#chocolate'))
    (rdflib.URIRef('http://example.com/#alice'), rdflib.URIRef('http://example.com/#likes'), rdflib.URIRef('http://example.com/#meat'))
    (rdflib.URIRef('http://example.com/#alice'), rdflib.URIRef('http://example.com/#dislikes'), rdflib.URIRef('http://example.com/#pizza'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble finding a clear explanation of connection pooling. I'm building an app
I'm having trouble finding a clear answer to this question so I thought I'd
I am having trouble finding clear and reliable examples of connecting to a PostgreSQL
I am having trouble finding clear documentation on how to set up a batch
I'm having trouble finding out what is new in Razor 2.x. Does anyone know?
Having trouble finding an explanation in the docs, would someone be kind enough to
I'm having trouble finding any resource for adding ctrl-z undo capability to a Flex
I'm having trouble finding/getting any logging output from a web service. I have a
I am having trouble finding information related to which i should choose, OpenGL ES
I'm having trouble finding information online for creating a object in javascript and pointing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.