Skip to content

jonathan1440/RPDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RPDB

A relational database using python and json

This may actually be better described as a relational interpreter.

Brief example

This is explaied below in Conceptual overview mem_seg = newMemorySegment()
person = Noun(mem_seg, "person").addr
bob = Noun(mem_seg, "Bob", person).addr
billy = Noun(mem_seg, "Billy", person).addr
siblings = LinkingVerb(mem_seg, "is siblings").addr
Link(mem_seg, bob, siblings, billy)
write_mem_seg(mem_seg, "test.json")
mem_seg = load_mem_seg("test.json")

Conceptual overview

The premise is that all systems can be described using objects and relations between those objects. There are three classes I made to make such descriptions programmatically. I have given them names from grammar because that was the easiest way for me to summarize it for myself.
Each of these classes needs to be passed a MemorySegment object. MemorySegment is not designed specifically for this project, and there is a bit of extra setup needed, so use newMemorySegment to get a MemorySegment object to pass to new instances of the classes below.
mem_seg = newMemorySegment()
All instances of the below classes are referenced by their "address" (index) in the MemorySegment.

  • Noun - This is the "thing" or "object." Every Noun has a name: person = Noun(mem_seg, "person").addr
    Each Noun can optionally be an instance_of another Noun:
    bob = Noun(mem_seg, "Bob", person).addr
    billy = Noun(mem_seg, "Billy", person).addr
  • LinkingVerb - These are words/phrases that are the types of relations, or "links", that can be made (eg "is a", "are", "owns", "was").
    is_a = LinkingVerb(mem_seg, "is a").addr
    'siblings = LinkingVerb(mem_seg, "is siblings").addr`
  • Link - This is what relates Nouns to each other: Link(mem_seg, bob, siblings, billy) - read as "Bob is siblings with Billy"
    When a new Noun is initialized, if the instance_of parameter is not None, it creates a Link between itself and the instance_of``Noun: Link(self.addr, is_a, self.instance_of)
    It is possible to create a Link between any of these three classes, although I'm considering removing the ability to do so with Links.

All instances of the above classes keep a list of the addresses of Links they are involved in in their attribute .links.

Class structure

  • MemorySegment(iterable=None, empty_values=None) extends list
    • .store_obj(object_, addr=None) - returns addr where object was stored in list.
    • .delete_obj(add) - removes object at addr from list.
    • .check_empty_values() - find skipped addresses in list.
    • .search(attr, value) - return list of objects in list with attr equal to value.
  • Noun(mem, name, instance_of=None, addr=None, links=None)
    • .mem
    • .name
    • .instance_of
    • .addr
    • .links
  • LinkingVerb(mem, name, addr=None, links=None)
    • .mem
    • .name
    • .addr
    • .links
  • Link(mem, thing1, linking_verb, thing2, addr=None, links=None)
    • .mem
    • .thing1
    • .linking_verb
    • .thing2
    • .links
  • Noun, Link, and LinkingVerb all share:
    • .__dict__()
    • .delete() - use instead of del <Noun/LinkingVerb/Link>.
    • .add_link(link_addr) - adds link_addr to self.links. This is done automatically every time a new Link is created.
    • .remove_link(link_addr) - removes link_addr from self.links. Called by Link.delete().
    • .list_links() - return list of Link objects in self.links.
    • .list_linked() - return list of objects involved in links in self.links.

About

A relational database using python and json

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages