How to define a simple Address attribute in TypeDB? - vaticle-typedb

I'm just getting started with TypeDB and have a basic question about the schema concepts:
How would I model that a Person has an Address? I.e. a composite attribute like an address that is composed of 3 values:
city,
street,
ZIP code?
My understanding is that an attribute can have exactly ONE value definition, but it can own any number of other attributes.
My attempts:
street sub attribute, value string;
city sub attribute, value string;
zip sub attribute, value long;
(1) Attribute without value?
address sub attribute,
// value ... (does not make sense here) ???
owns street,
owns city,
owns zip;
person sub entity,
owns address;
(2) Modeled as relation?
address sub relation,
relates street,
relates city,
relates zip,
relates subject; // ???
person sub entity,
plays address:subject;
(3) As entity?
address sub entity,
owns street,
owns city,
owns zip;
person sub entity,
owns address; // ??? is owning another entity possible?
Which one (if any) would be the recommended way to go?

An address works best as an entity because, as #2bigpigs said, an address is an entity as it has a distinct existence in the domain. Other examples of an entity include an organisation, a location or a person. You can see that an address fits right in among those.

Related

how to update one to many relationship in ddb

Let's assume a bank and address example:
class Address:
id: string
street: string
city: string
class BankBranch:
id: string
name: string
employee_count: number
address: object
Address is its own table because other services should be able to use instances of this Address table. For example each BankBranch has an address. Now when I store a BankBranch instance in DBB I'd imagine it will look like this:
{
name: "BranchXYZ",
id: "123456",
employee_count: 5,
address: {
street: "123 main st",
city: "maincity",
id: "456789"
}
}
and the address instance looks like this:
{
street: "123 main st",
city: "maincity",
id: "456789",
}
What's the best procedure to keep the data consistent? If I update the address instance, do I issue another call to the BankBranch and update it there as well? So one update operation is actually 2 database operations?
Or instead of saving the entire address object I just save the id (like a foreign key) and then when I go I get request to the BankBranch instance I issue another request to the address issue? That sounds a bit expensive.
You’re asking if you should denormalize or not. That depends on many factors.
First, are you doing this at a scale where it actually matters? You say it’s expensive. At highest price EC lookups are about 12.5c per million lookups. How many secondary lookups would you really be doing?
Meanwhile you haven’t explained in depth why the address has to be in another table. Seems like it’s an intrinsic part of the branch. You’re really going to have other services referring to the address by some random ID number unrelated to the branch? Can’t they refer to it by branch ID and pull out the address?

Cannot select a record in Global address book addresses by NON SysAdm user

Opening a Home/Common/Global address book Global address book form I get this error
Cannot create a record in Global address book (DirPartyTable). Party
ID: ******, ***. The record already exists.
With my user (is not sysADM) I'm NOT able to select a record in CompanyInfo.
I done a debug (Debug-NO_SysADM), my user is not able to get a record in ComanyInfo by this query
select companyInfo
where companyInfo.DataArea = _currentCompany_
This query NOT get an helpful record, but actually the record in CompanyInfo Table exist.
There is any parameter to exclude some roles/user to check-find record in this table? Or there is any way to justify this.
Thanks

Grakn, create entity composed by entity?

I'm very new on GRAKN.AI and I'm wondering if in a GRAKN's graph I can create an "entity" composed by an "enitity". I know I can do the following code:
table sub entity
has book;
book sub resources datatype string;
But can I relate the "book" as an entity to the "table" ??
I need to have "book" as a complex concept and not as a simple resource.
Thanks,
Davide.
An alternative solution is to go through a relationship which allows you to define things more explicitly. For example,
To define a relationship you start by defining roles which provide context for how things relate to each other. For example:
insert
thing-on-top-of-table sub role;
table-with-thing-on-top sub role;
You then say how these roles link to the relationship and to the entities:
insert
sits-on sub relation
relates thing-on-top-of-table
relates table-with-thing-on-top;
table plays table-with-thing-on-top;
book plays thing-on-top-of-table;
The above is pretty much the schema of your simple knowledge base.
Now we can add some data. Let's say some book is on top of some table:
insert
$book isa book;
$table isa table;
(thing-on-top-of-table: $book, table-with-thing-on-top: $table) isa sits-on
Naturally you can expand things from here. For example you can give your book a title via a resource.
Side Note: Resources Vs Entities
The basic rule of thumb for relating something as a resource or as another entity depends on how much information you want to express in the model as well as if something can be defined by a data literal (e.g. String, Int, Long, etc . . . ).
For example a book is an entity because it is made up of multiple resources which help identify the book. I.e. the title, isbn, etc. . . those resources on the other hand are simple data values. A title is nothing but a string so there is no reason to make the title an entity, that should be fine as just a resource.
You couold model two entites bookand table and have a relation that you could call something like belongs and add the roles you need e.g. book-role and table-role
If the concepts are hierarchically related you can use inheritance.
table sub entity
has some property
book sub table
has additional property
Inheritance is usefull for classification you can easily understand that two sub entities are related and both can be retrieved by querying the parent.
match $t isa table;
would return the books as they are children entities of table.

GQL Projection Query on Embedded Entity

Say I have a User entity with an embedded entity address which contains a house number property and a street property. How can I write a GQL projection query that will filter based on name and return a list of addresses ?
Sample Data:
The projection query I am trying to write:
SELECT address FROM User WHERE name = Bob
This should return two addresses but it returns no results.
Thanks to anyone who answers !
You can't project the entire entity value, but you can project the individual properties in the entity value, e.g.:
SELECT address.houseNumber FROM User WHERE name = Bob

Business Objects/Custom Classes DAL Design

I need some advice on how to handle this scenario. My application has many tables and custom classes mapped to those tables. Let's use the following as an example (pseudo-code):
Public Class Country
Name As String
Language As String
Capital As String
President As String
Public Class State
Name As String
Capital As String
Country As String
Public Class City
Name As String
State As String
Country As String
Retrieving an individual object of any of these classes is straight forward. Retrieving lists of any of these objects is straight forward as well.
Where I need guidance is how to retrieve a combination of these objects. For example we may need to display a list of City Names and Country Presidents (excludes the State Class). What object should I use to hold that data? I want to avoid retrieving the State data because trips to the database are expensive. I typically present the information using repeaters so I also need an object that is easily bindable to a repeater.
Thanks for your help.

Resources