Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Org.eclipse.higgins.js.pds.client API usage example"

(0:pushEvalRule (:me, rule #2 above, "female"))
(Execution)
 
(23 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{#eclipseproject:technology.higgins|eclipse_custom_style.css}}
 
{{#eclipseproject:technology.higgins|eclipse_custom_style.css}}
  
We show an example of calling getAttributes, calling setAttributes and then calling getAttributes a second time. In all cases we read/write the same two attributes in the nytimes.com namespace, bFirstName and phone.
+
We show an example of calling getAttributes and then calling setAttributes. In all cases we read/write the same two attributes in the nytimes.com namespace, bFirstName and phone.
 +
 
 +
TODO: a more realistic scenario would be showing a call to getCredentials() and then a call to setCredentials() followed by the getAttributes () and setAttributes () calls that are documented here.
  
 
==Initial State==
 
==Initial State==
  
 
===Contexts===
 
===Contexts===
[[Image:Pdsclient example 2.0.101.png]]
+
[[Image:Pdsclient api example initial 2.0.108.png|center]]
  
 
===NYTimes template===
 
===NYTimes template===
Line 42: Line 44:
 
               ] .
 
               ] .
  
== call getAttributes() ==
+
== call getAttributes(domain, attributes[], where[], future) ==
  
 
=== Call ===
 
=== Call ===
Example call to getAttributes (domain, audience, attributes[], where[], future)
+
Example call to getAttributes:
  
* atts[0] := (http://nytimes#gender, false, nil)   // a phone number
+
* atts[0] := {id="#gender"}      // gender (with nil namespace)
* atts[1] := (http://nytimes#bFirstName, false, nil)   // "billing first name"
+
* atts[1] := {id="#bFirstName"}   // "billing first name" (with nil namespace)
* '''getAttributes''' (''"nytimes.com", nil, atts, nil, nil'')
+
* '''getAttributes''' (''future, "nytimes.com", atts[]'')
  
 
=== Execution ===
 
=== Execution ===
Line 56: Line 58:
 
* call findRoles()
 
* call findRoles()
 
** result:  
 
** result:  
*** ((p:eCommerce, (nytimes.com#gender, nil, nil))
+
*** [[r=p:eCommerce, a={#gender}]
*** (p:Buyer, (nytimes.com#gender, nil, nil)))
+
*** [r=p:Buyer, a={#gender}]]
 
* call sortByRole()
 
* call sortByRole()
 
** result:  
 
** result:  
*** ((p:eCommerce, (nytimes.com#gender, nil, nil))
+
*** [[r=p:eCommerce, a={#gender}]
*** (p:Buyer, (nytimes.com#bFirstName, nil, nil)))
+
*** [r=p:Buyer, a={#gender}]]
 
* Try to pull attributes from #me person in the nytimes.com
 
* Try to pull attributes from #me person in the nytimes.com
 
** result: no result: the nytimes.com context doesn't yet exist
 
** result: no result: the nytimes.com context doesn't yet exist
Line 69: Line 71:
 
** result: no attribute/values found
 
** result: no attribute/values found
  
== call setAttributes() ==
+
== call setAttributes(''future, domain, attributes[]'') ==
  
 
=== Call ===
 
=== Call ===
  
Example call to setAttributes (domain, attributes[])
+
Example call to setAttributes:
  
* attVals[0] := (http://nytimes#gender, "female")  
+
''attVals[]'' is an array of Attributes:
* attVals[1] := (http://nytimes#bFirstName, "Alice") // "billing first name"
+
* attVals[0] := {id="#gender", value=["female"])  
 +
* attVals[1] := {id=h"#bFirstName", value=["Alice"]) // "billing first name"
  
 
* '''setAttributes''' ("nytimes.com", attvals[])
 
* '''setAttributes''' ("nytimes.com", attvals[])
Line 89: Line 92:
 
** result: newPersonRole == p:Ecommerce
 
** result: newPersonRole == p:Ecommerce
 
* attributes[] := extractAttributes ()
 
* attributes[] := extractAttributes ()
** result: attributes[] == (http://nytimes.com#gender, http://nytimes.com#bFirstName)
+
** result: attributes[] == (#gender, #bFirstName)
 
* rolesAtts[] := findRoles()
 
* rolesAtts[] := findRoles()
** result: rolesAtts[] == ((p:Ecommerce, http://nytimes.com#gender), (p:Buyer, http://nytimes.com#bFirstName))
+
** result: rolesAtts[] == [{r=["p:Ecommerce"], a=[{id=#gender}]}, {r=["p:Buyer"], a=[{id=#bFirstName}]}]
 
* sortByRole
 
* sortByRole
** result: rolesAtts[] == ((p:Ecommerce, http://nytimes.com#gender), (p:Buyer, http://nytimes.com#bFirstName))
+
** result: rolesAtts[] == [{r=["p:Ecommerce"], a=[{id=#gender}]}, {r=["p:Buyer"], a=[{id=#bFirstName}]}]
 
* person := http://azigo.com/ptrevithick/nytimes.com#me
 
* person := http://azigo.com/ptrevithick/nytimes.com#me
 
* Since ''person'' doesn't exist we create the statements:
 
* Since ''person'' doesn't exist we create the statements:
 
** (subj=:me pred=rdf:type obj=persona:Person) in ''context''
 
** (subj=:me pred=rdf:type obj=persona:Person) in ''context''
** (subj=:me pred=p:role obj=(''newPersonRole''==persona:Ecommerce)) in ''context''
+
** (subj=:me pred=p:role obj=(''newPersonRole''=="p:Ecommerce")) in ''context''
* Loop[0] ra==(p:Ecommerce, http://nytimes.com#gender) // Loop: For every pair ra in rolesAtts...
+
* Loop[0] ra[0]=={r=["p:Ecommerce"], a=[{id=#gender, value=["female"]}]} // Loop: For every pair ra in rolesAtts...
** targetPersons[] := findPersonsByRole (person, p:Ecommerce)
+
** targetPersons[] := findPersonsByRole (person, "p:Ecommerce")
 
*** result: targetPersons[0] == <the :me person created above>; targetPersons[] is of size == 1
 
*** result: targetPersons[0] == <the :me person created above>; targetPersons[] is of size == 1
 
** person == targetPersons[0]
 
** person == targetPersons[0]
** partialAttVals[] := subsetAttVals ()
+
** Loop: a=={id=#gender value=["female"]}
*** result: partialAttVals[] == (http://nytimes.com#gender, "female")
+
*** rule := getRule (template=http://azigo.com/sys/template/nytimes.com, #gender)
** Loop: av==(http://nytimes.com#gender, "female")
+
*** class := getNamespace()
+
**** result: class=="http://nytimes.com"
+
*** latt : getLocalAtt()
+
**** result: latt=="phone"
+
*** rule := getRule (template=http://azigo.com/sys/template/nytimes.com, class=http://nytimes.com, att="gender")
+
 
**** result rule==(see "rule #2" in Initial State section above)
 
**** result rule==(see "rule #2" in Initial State section above)
 
*** '''0:pushEvalRule'''(person=:me, rule #2 above, value[0]="female")
 
*** '''0:pushEvalRule'''(person=:me, rule #2 above, value[0]="female")
 
** EndLoop
 
** EndLoop
* Loop[1] ra==(p:Buyer, http://nytimes.com#bFirstName)
+
* Loop[0] ra[0]=={r=["p:Buyer"], a=[{id=#bFirstName, value=["Alice"]}]} // Loop: For every pair ra in rolesAtts...
** targetPersons[] := findPersonsByRole (person, p:Buyer)
+
** targetPersons[] := findPersonsByRole (person, "p:Buyer")
 
*** result: targetPersons[] is of size == 0
 
*** result: targetPersons[] is of size == 0
 
** create new person and set the value of its role to p:Buyer
 
** create new person and set the value of its role to p:Buyer
** add new person to newPersons[]
+
*** new person is :7643
** partialAttVals[] := subsetAttVals ()
+
** add new person :7643 to newPersons[]
*** result: partialAttVals[] == (http://nytimes.com#bFirstName, "Alice")
+
** Loop: a=={id=#bFirstName value=["Alice"]}
** Loop: av==(http://nytimes.com#bFirstName, "Alice")
+
*** rule := getRule (template=http://azigo.com/sys/template/nytimes.com, #bFirstName)
*** class := getNamespace()
+
**** result: class=="http://nytimes.com"
+
*** latt : getLocalAtt()
+
**** result: latt=="phone"
+
*** rule := getRule (template=http://azigo.com/sys/template/nytimes.com, class=http://nytimes.com, att="bFirstName")
+
 
**** result rule==(see "rule #1" in Initial State section above)
 
**** result rule==(see "rule #1" in Initial State section above)
*** '''1:pushEvalRule'''(person=<new person>, rule #1 above, value[0]="Alice")
+
*** '''1:pushEvalRule'''(person=:7643, rule #1 above, value[0]="Alice")
 
** EndLoop
 
** EndLoop
 
* EndLoop
 
* EndLoop
Line 149: Line 141:
  
 
===== pushRoleLiteral (person=:me, rule #3, "female") =====
 
===== pushRoleLiteral (person=:me, rule #3, "female") =====
* result: attached foaf:gender attribute to :me and sets value to "female"
+
* mappedAtt := getruleField()
 +
** result: mappedAtt == foaf:gender
 +
* add new foaf:gender attribute to :me and sets value to "female"
 +
 
 +
==== 1:pushEvalRule (person= :7643, rule #1 above, "Alice") ====
 +
* mappingRule := getRuleField()
 +
** result: mappingRule == rolePathLiteral
 +
* call pushRoleLiteral(template, 7643, rule #1, "Alice")
  
==== 1:pushEvalRule (<new person>, rule #1 above, "Alice") ====
+
===== pushRulePathLiteral(template, 7643, rule #1, "Alice") =====
 +
* path := getRuleField ()
 +
** result: path == "v:n"
 +
* since :7643 doesn't have a v:n attribute then we create a v:Name object
 +
** result obj:= new v:Name
 +
* mappedAtt := getRuleField ()
 +
** result: mappedAtt == v:given-name
 +
* since obj is new it doesn't have a v:given-name we add v:given-name to it
  
 
== Final State ==
 
== Final State ==
 
Red is newly created context
 
Red is newly created context
[[Image:Pdsclient api final state 2.0.105.png|center]]
+
[[Image:Pdsclient api example final 2.0.108.png|center]]

Latest revision as of 13:02, 29 September 2011

{{#eclipseproject:technology.higgins|eclipse_custom_style.css}}

We show an example of calling getAttributes and then calling setAttributes. In all cases we read/write the same two attributes in the nytimes.com namespace, bFirstName and phone.

TODO: a more realistic scenario would be showing a call to getCredentials() and then a call to setCredentials() followed by the getAttributes () and setAttributes () calls that are documented here.

Initial State

Contexts

Pdsclient api example initial 2.0.108.png

NYTimes template

The template context http://azigo.com/sys/templates/nytimes.com contains (among other things) a class named "http://nytimes.com" that has the following mapping rules:

 :NYTimesPerson
     a       owl:Class ;
     rdfs:subClassOf <http://www.eclipse.org/higgins/ontologies/2010/6/higgins#Person> ;

rule #1:

     map:nameRule
             [ rdf:type map:rolePathLiteral ;
               map:mappedAtt <http://www.w3.org/2006/vcard/ns#given-name> ;
               map:path <http://www.w3.org/2006/vcard/ns#n> ;
               map:predicate :bFirstName ;
               map:role <http://www.eclipse.org/higgins/ontologies/2010/6/persona#Buyer>
             ] ;

rule #2:

     map:relationshipsRule
             [ rdf:type map:roleSameAs ;
               map:equivalentAttribute
                       fp:gender ;
               map:predicate :gender ;
               map:role <http://www.eclipse.org/higgins/ontologies/2010/6/persona#Ecommerce>
             ] ;

FlatPersonaPerson (relevant sections only)

rule #3:

     map:relationshipsRule
             [ rdf:type map:roleLiteral ;
               map:mappedAtt <http://xmlns.com/foaf/0.1/gender> ;
               map:predicate :gender ;
               map:role map:roleParam
             ] .

call getAttributes(domain, attributes[], where[], future)

Call

Example call to getAttributes:

  • atts[0] := {id="#gender"} // gender (with nil namespace)
  • atts[1] := {id="#bFirstName"} // "billing first name" (with nil namespace)
  • getAttributes (future, "nytimes.com", atts[])

Execution

  • context := getConnectionContext ()
  • call findRoles()
    • result:
      • [[r=p:eCommerce, a={#gender}]
      • [r=p:Buyer, a={#gender}]]
  • call sortByRole()
    • result:
      • [[r=p:eCommerce, a={#gender}]
      • [r=p:Buyer, a={#gender}]]
  • Try to pull attributes from #me person in the nytimes.com
    • result: no result: the nytimes.com context doesn't yet exist
  • Try to pull attributes from #me person in root context
    • call findPersonByRole()
    • result: nil (no persons found that match role)
    • result: no attribute/values found

call setAttributes(future, domain, attributes[])

Call

Example call to setAttributes:

attVals[] is an array of Attributes:

  • attVals[0] := {id="#gender", value=["female"])
  • attVals[1] := {id=h"#bFirstName", value=["Alice"]) // "billing first name"
  • setAttributes ("nytimes.com", attvals[])

Execution

  • context := getConnectionContext ()
  • template := getConnectionTemplate ()
  • Since context doesn't exist, create it from template
  • newPersonRole := value of role attribute of Participant ContextPrototype
    • result: newPersonRole == p:Ecommerce
  • attributes[] := extractAttributes ()
    • result: attributes[] == (#gender, #bFirstName)
  • rolesAtts[] := findRoles()
    • result: rolesAtts[] == [{r=["p:Ecommerce"], a=[{id=#gender}]}, {r=["p:Buyer"], a=[{id=#bFirstName}]}]
  • sortByRole
    • result: rolesAtts[] == [{r=["p:Ecommerce"], a=[{id=#gender}]}, {r=["p:Buyer"], a=[{id=#bFirstName}]}]
  • person := http://azigo.com/ptrevithick/nytimes.com#me
  • Since person doesn't exist we create the statements:
    • (subj=:me pred=rdf:type obj=persona:Person) in context
    • (subj=:me pred=p:role obj=(newPersonRole=="p:Ecommerce")) in context
  • Loop[0] ra[0]=={r=["p:Ecommerce"], a=[{id=#gender, value=["female"]}]} // Loop: For every pair ra in rolesAtts...
    • targetPersons[] := findPersonsByRole (person, "p:Ecommerce")
      • result: targetPersons[0] == <the :me person created above>; targetPersons[] is of size == 1
    • person == targetPersons[0]
    • Loop: a=={id=#gender value=["female"]}
    • EndLoop
  • Loop[0] ra[0]=={r=["p:Buyer"], a=[{id=#bFirstName, value=["Alice"]}]} // Loop: For every pair ra in rolesAtts...
    • targetPersons[] := findPersonsByRole (person, "p:Buyer")
      • result: targetPersons[] is of size == 0
    • create new person and set the value of its role to p:Buyer
      • new person is :7643
    • add new person :7643 to newPersons[]
    • Loop: a=={id=#bFirstName value=["Alice"]}
      • rule := getRule (template=http://azigo.com/sys/template/nytimes.com, #bFirstName)
        • result rule==(see "rule #1" in Initial State section above)
      • 1:pushEvalRule(person=:7643, rule #1 above, value[0]="Alice")
    • EndLoop
  • EndLoop
  • Loop for every person np in newPersons[]
    • result: add an h:correlation link from :me to <new person>

0:pushEvalRule (:me, rule #2 above, "female")

  • mappingRule := getRuleName()
    • result: mappingRule == "roleSameAs" so call pushRoleSameAs (person=:me, rule #2 above, "female")
pushRuleSameAs (template, person=:me, rule, value)
  • equivAtt := getRuleField (rule, map:equivalentAttribute)
    • result: equivAtt == fp:gender
  • newRule := findRule (template, eqivAtt)
    • result: returns rule #3 above!
  • pushEvalRule (person=:me, newRule, "Alice") // recursion

0:0: pushEvalRule (:me, rule #3 above, "female")

  • mappingRule := getRuleName()
    • result: mappingRule == "roleLiteral" so call pushRoleLiteral (person=:me, rule #3 above, "female")
pushRoleLiteral (person=:me, rule #3, "female")
  • mappedAtt := getruleField()
    • result: mappedAtt == foaf:gender
  • add new foaf:gender attribute to :me and sets value to "female"

1:pushEvalRule (person= :7643, rule #1 above, "Alice")

  • mappingRule := getRuleField()
    • result: mappingRule == rolePathLiteral
  • call pushRoleLiteral(template, 7643, rule #1, "Alice")
pushRulePathLiteral(template, 7643, rule #1, "Alice")
  • path := getRuleField ()
    • result: path == "v:n"
  • since :7643 doesn't have a v:n attribute then we create a v:Name object
    • result obj:= new v:Name
  • mappedAtt := getRuleField ()
    • result: mappedAtt == v:given-name
  • since obj is new it doesn't have a v:given-name we add v:given-name to it

Final State

Red is newly created context

Pdsclient api example final 2.0.108.png

Back to the top