I've looked at how to do data modelling and have some questions in regards to the use of roles specifically in Grakn.
Let's take a simple case. I have a Company, and that Company can be a Distributor, Supplier, Customer, or any such combination. Company A could be a distributor and a customer at the same time.
If I use a relational database, I would have a table for CompanyS and then tables for SupplierS, CustomerS, etc, which then would reference the Company table.
However, I want to start with a Company and know what roles it is playing without having to create these extra tables. So that in my application I can know that a company is both a distributor and a supplier in a single query.
There's a few ways I can think how to do it, but as I feel this problem domain is so common there must be some best practices for modelling these concepts.
So I am looking for common patterns or strategies to model and name certain entity roles. I am using Grakn. Any help is appreciated.
If I understand right, you mean to ask for general rules of thumb for choosing roles. Choosing roles is also caught up in choosing the naming for your relations, entities and attributes. In the case given, company is ubiquitously modelled as an entity, but there are plenty of examples where you may realise that you had the naming for an entity/relation/role mixed up.
Try this for general guidance:
Entity: Should be capable of its own existence in the world. Can be an abstract concept. Use abstract nouns (company, religion), collective nouns, common nouns.
Relation: Should have existence dependent upon the existence of its role players. Use abstract nouns (marriage, membership, hierarchy) and verbal nouns (authorship, ownership, ).
Role: Should describe a behaviour within the context of a relation. You can try using this sentence: A [entity] behaves like a [role] in a [relation]. For example a station behaves like a stop in a train-route. Should use nouns.
Attributes: Should describe a quantity only e.g. name (string), age (long), colour (string), is-green (boolean), verbose (boolean), is-running (boolean), score (double). Typically nouns or verbs. Anything goes if it describes a value well.
If you struggle to find a noun, use a name that ends with a noun, but prepend with a descriptive term, like authored-book.
At times it may be easier to think of relations in terms of verbs too -- as long as they are gerund tense. For example:
faceting sub relation,
relates facet-assignment,
relates assigned-facet.
listing sub relation,
relates list-assignment,
relates assigned-list.
Related
The thesis Ontological foundations for structural conceptual models states that
"Every relationally dependent entity (role and role mixins) must be
connected to an association end of a «mediation» relation."
(p.332). Why is a <<member of>> relation not enough to satisfy the relational dependance?
There is indeed a pattern of roles and role mixins for members of collectives, however, the membership to the collective has a truthmaker of its own.
If you only use the «memberOf» relation you'll be hiding the relator of "membership" that makes it true that "the endurant plays the role of a member of some collective". In order to have the complete pattern, you should capture the relator and the «mediation» relation between the role and the relator.
Notice that this is a pattern specific to the case involving roles (e.g., employees, students, band members). You can still have cases where there may not be a relator as the truthmaker of the «memberOf» relation.
Take, for instance, the collective Forest whose members are instances of Tree. In this case, you would not be interested in capturing the "membership" between trees and forests and that is OK as Tree should not be a role, but a category, kind or subkind. (hint: the truthmaker here is something more "tricky")
I'm searching for a solution to model a "can-be" relationship.
E.g.: A User can be Special User.
Any suggestions?
Types for entities can be viewed (results) as one of the following two things:
Relationships
Fields
The types that results in fields are usually seen as functional redundancy, where different rows/records in a table can have the same type. For example, the sex/gender of a user, or access privileges or permission level from a user as well.
If, however, this field has attributes/properties, so we have a new entity. In this case, users would be relating to, for example, address, which may have the street name, house number, among other things. Or, in your case, if Special User has attributes/properties, we have a "Special Users" entity. The cardinality here depends on how many types a user can have, and that takes into account the problem context.
As you say that a user "can be", it means it "can not be" too. You could:
Set a nullable functional redundancy field in Users entity or,
Set an entity "Types of Users" and create a relationship N-N for
"Users". In this case, you would have an intermediate table that
would allow or not the connection between the two entities.
In both approaches you have the ability to add new types of users in the future without effort.
There is a third case, however, referred to as partitioning, where we have types and subtypes of entities. In this case, entities subtypes inherit fields of their super entities. I believe this is not your case here.
If you have any questions, please comment and I will answer.
Suppose I have some medical software that tracks billing and medical procedures for patients. Each patient then has three important groups of attributes.
Shared attributes - name, age, gender, patient number, etc.
Billing Attributes - address, account number, balance, etc
Medical Attributes - blood pressure, surgeries, blood type, etc.
I have a single ActiveRecord Patient model with all of the above attributes. I could then have a PatientBillingDetails controller and a PatientMedicalDetails controller to distinguish between the two. Should I also create two more models to correspond to each controller, or just have each controller draw from the single Patient model. If creating two new models, what is the best/simplest way to have them use only the appropriate attributes?
To answer your question directly, while Rails tutorials like to silo the information into one controller for one model, my 5+ years experience writing large enterprise applications in Rails has shown me that the controllers you build relate to the views you need to show, rather than a one-to-one relationship with models. Thus, it would seem more than sensical to create several controllers for each aspect of your Patient model.
It seems to me, however, that the real issue is that your Patient model is overloaded by trying to do too many things at once. I would suggest you normalize out some of the information into their own models--particularly where you may need a "has many" relationship, like medical attributes as recorded on different dates.
To give a better answer, I'd need more information on what it is your software is trying to do, particularly what category of "medical software" you are trying to write, and if this is a side utility for a specialty purpose or a general purpose EHR or Medical Billing Application.
I have a situation where I have Model A that has a variety of properties. I have discovered that some of the properties are similar across other models. My thought was I could create Model B and Model C and have Model A be a composite with a Model B property and a Model C property.
Just trying to determine if this is the best way to handle this situation.
It's definitely valid in certain situations. Let's say you have a Person class and a Company class, and they have the common properties streetNumber, streetName, postcode, etc. It makes sense to make a new model class called Address that both Person and Company contain. Inheritance is the completely wrong way to go in such a situation.
When properties (e.g. state) are the elements of commonality, I definately tend towards using composition rather than inheritance. When using inheritance, its perhaps best to wait until behavior is the commonality, and overrides are needed now or imminently.
What you're looking at is creating an Aggregate Root. A core paradigm of the Domain Driven Design (DDD) principals.
Certain models in your app will appear to belong "at the top" or "as root" to other objects. For example in the case of customers you might have a Contact model which then contains a collection of ContactPoints (names, addresses, etc).
Or a Post (in the case of a blog), which contains a collection of Comments, a Tite, Body and a TagSet (for tagging). Notice how the items i've highlighted as objects - these are other model types as opposed to simple types (strings, ints, etc).
The trick will come when and how you decide to 'fill' these Aggregate Root trees/graphs. Ie. How will you query just for a single TagSet? Will you go to the top and get the corresponding Post first? Maybe you just wanted to rename the tag "aspnetmvc" to "asp.net-mvc" for all Posts so you want to cut in and just get the TagSet item.
The MVC Storefront tutorial has some good examples of this pattern. Take a look if you can.
In my domain:
Users have many Bills
Bills have many BillItems (and therefore Users have many BillItems through Bills)
Every BillItem is one of:
Call
SMS (text message)
MMS (multimedia message)
Data
Here are the properties of each individual BillItem (some are common):
alt text http://dl.dropbox.com/u/2792776/screenshots/2010-04-13_2146-1.png
My question is whether I should model this arrangement with single-table inheritance (i.e., one "bill_items" table with a "type" column) or polymorphism (separate tables for each BillItem type), and why.
I would go with a Polymorphic association as there are enough fields already that don't apply to all/most of the items. STI will just waste a lot of space, but ignoring optimization, it's also a very rigid design as the most natural way to extend on that design when more fields are required will be to add them to the table.
Polymorphic association on the other hand only specifies a contract that all implementors must follow. In this case the contract only says that an item must be billable, and allows each individual type of item to evolve independently. If there is logic to be shared among these different classes, it might be better to just convert it into a module and include that.