[Jslib] Re: working with rdf.js

Martin T. Kutschker Martin.T.Kutschker@blackbox.net
Wed, 30 May 2001 09:17:01 +0200


This is a multi-part message in MIME format.

------=_NextPart_000_000F_01C0E8E9.490719C0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


  Kevin Watt <wattk@seattleu.edu> schrieb in im Newsbeitrag: =
public.mozdev.jslib/001701c0e871$6ca6e7c0$6a3f11ac@dd.seattleu.edu...
  Hi Guys,

  I was thinking of adding the following function to add a resource =
instead of a literal... Would that accomplish the resource=3D I'm hoping =
for?  I wrote some code, but have to go to class.  Just thought I'd ask =
and see if it made sense to y'all.

    setRefAttribute : function(aNode, name, bNode) //bNode was value - =
instead of a literal, make it a reference::
    {
      alert ('in setRefAttribute');
      var realnode =3D this._getRealNode(aNode);
      var newnode =3D this.RDF.GetResource(realnode);
      var oldvalue =3D this.getAttribute(realnode, name);
I'd change this to doesAttributeExist (or doesXXXExist, see below).
  =20
      //get real node for our destination, as well
      var Brealnode =3D this._getRealNode(bNode);
      var Bnewnode =3D this.RDF.GetResource(Brealnode);

      if(newnode) {
        // Add an assertion to the RDF datasource for each property of =
the resource
        if(oldvalue) {=20
          this.dsource.Change(newnode,
              this.RDF.GetResource(this.nc + name),
              this.RDF.GetResource(oldvalue),
              this.RDF.GetResource(Bnewnode) );
        } else {
          this.dsource.Assert(newnode,
              this.RDF.GetResource(this.nc + name),
              this.RDF.GetResource(Bnewnode),
              true );
             =20
          alert ('added new Assert(' + newnode + '), ' + =
this.RDF.GetResource(this.nc + name) + ', ' +
              this.RDF.GetResource(Bnewnode) + ', true');
        }
      }
    }

  Any suggestions welcome,
Looks ok to me. I see only a problem with the old implementation of =
doesAttributeExist. rdf.js treats a statement with a literal as object =
as "attribute", but the targets (as you know) may also be resources. So =
I recommend to change the method to this (perhaps reanming it as well):

  doesAttributeExist : function(aNode, name)
  {
    var realnode =3D this._getRealNode(aNode);

    var itemRes =3D this.RDF.GetResource(this.nc + name);
    if (!itemRes) return null;

    var IDRes =3D this.RDF.GetResource(realnode);
    if (!IDRes) return null;
       =20
    var thisNode =3D this.dsource.GetTarget(IDRes, itemRes, true);
    if (thisNode) {
      return true;
    }
    return false;
  },

What also makes me think is the naming convention in rdf.js (after =
reading the RDF docs more carefully). I think that the use of "node" in =
rdf.js clashes with Mozilla's use of this word. Obviously rdf.js =
simplifies things (or it would not be needed at all), but it shoud =
either use a general naming scheme or restrict itself to tree structures =
(root, leaves, branches, ... and nodes?).

Masi

------=_NextPart_000_000F_01C0E8E9.490719C0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2722.2800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV>Kevin Watt &lt;<A=20
  href=3D"mailto:wattk@seattleu.edu">wattk@seattleu.edu</A>&gt; schrieb =
in im=20
  Newsbeitrag: <A=20
  =
href=3D"mailto:public.mozdev.jslib/001701c0e871$6ca6e7c0$6a3f11ac@dd.seat=
tleu.edu">public.mozdev.jslib/001701c0e871$6ca6e7c0$6a3f11ac@dd.seattleu.=
edu</A>...</DIV>
  <DIV><FONT face=3DArial size=3D2>Hi Guys,</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>I was thinking of adding the =
following function=20
  to add a resource instead of a literal... Would that accomplish the =
resource=3D=20
  I'm hoping for?&nbsp; I wrote some code, but have to go to =
class.&nbsp; Just=20
  thought I'd ask and see if it made sense to y'all.</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp; setRefAttribute : =
function(aNode, name,=20
  bNode) <A href=3D"file://bNode">//bNode</A> was value - instead of a =
literal,=20
  make it a reference::<BR>&nbsp; {<BR>&nbsp;&nbsp;&nbsp; alert ('in=20
  setRefAttribute');<BR>&nbsp;&nbsp;&nbsp; var realnode =3D=20
  this._getRealNode(aNode);<BR>&nbsp;&nbsp;&nbsp; var newnode =3D=20
  this.RDF.GetResource(realnode);<BR>&nbsp;&nbsp;&nbsp; var oldvalue =3D =

  this.getAttribute(realnode, name);</FONT></DIV></BLOCKQUOTE>
<DIV><FONT face=3D"Andale Mono" size=3D2>I'd change this to =
doesAttributeExist (or=20
doesXXXExist, see below).</FONT></DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV><FONT face=3DArial size=3D2>&nbsp;<BR>&nbsp;&nbsp;&nbsp; <A=20
  href=3D"file://get">//get</A> real node for our destination, as=20
  well<BR>&nbsp;&nbsp;&nbsp; var Brealnode =3D=20
  this._getRealNode(bNode);<BR>&nbsp;&nbsp;&nbsp; var Bnewnode =3D=20
  this.RDF.GetResource(Brealnode);</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; if(newnode)=20
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Add an assertion to the RDF =
datasource=20
  for each property of the resource<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  if(oldvalue) { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  =
this.dsource.Change(newnode,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;=20
  this.RDF.GetResource(this.nc +=20
  =
name),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;=20
  =
this.RDF.GetResource(oldvalue),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  this.RDF.GetResource(Bnewnode) );<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } =
else=20
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  =
this.dsource.Assert(newnode,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;=20
  this.RDF.GetResource(this.nc +=20
  =
name),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;=20
  =
this.RDF.GetResource(Bnewnode),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  true =
);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

  <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert ('added new =
Assert(' +=20
  newnode + '), ' + this.RDF.GetResource(this.nc + name) + ', '=20
  =
+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  this.RDF.GetResource(Bnewnode) + ', =
true');<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  }<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; }</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Any suggestions =
welcome,</FONT></DIV></BLOCKQUOTE>
<DIV><FONT face=3D"Andale Mono" size=3D2>Looks ok to me. I see only a =
problem with=20
the old implementation of doesAttributeExist. rdf.js treats a statement =
with a=20
literal as object as "attribute", but the targets (as you know) may also =
be=20
resources. So I recommend to change the method to this (perhaps reanming =
it as=20
well):</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Andale Mono" size=3D2>&nbsp; doesAttributeExist : =
function(aNode,=20
name)<BR>&nbsp; {</FONT></DIV>
<DIV><FONT face=3D"Andale Mono" size=3D2>&nbsp;&nbsp;&nbsp; var realnode =
=3D=20
this._getRealNode(aNode);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Andale Mono" size=3D2>&nbsp;&nbsp;&nbsp; var itemRes =
=3D=20
this.RDF.GetResource(this.nc + name);<BR>&nbsp;&nbsp;&nbsp; if =
(!itemRes) return=20
null;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Andale Mono" size=3D2>&nbsp;&nbsp;&nbsp; var IDRes =
=3D=20
this.RDF.GetResource(realnode);<BR>&nbsp;&nbsp;&nbsp; if (!IDRes) return =

null;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp; var=20
thisNode =3D this.dsource.GetTarget(IDRes, itemRes, =
true);<BR>&nbsp;&nbsp;&nbsp;=20
if (thisNode) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return=20
true;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; return =
false;<BR>&nbsp;=20
},<BR></FONT></DIV>
<DIV><FONT face=3D"Andale Mono" size=3D2>What also makes me think is the =
naming=20
convention in rdf.js (after reading the RDF docs more carefully). I =
think that=20
the use of "node" in rdf.js clashes with Mozilla's use of this word. =
Obviously=20
rdf.js simplifies things (or it would not be needed at all), but it =
shoud either=20
use a general naming scheme or restrict itself to tree structures (root, =
leaves,=20
branches, ... and nodes?).</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Andale Mono"><FONT=20
size=3D2>Masi</FONT></DIV></FONT></BODY></HTML>

------=_NextPart_000_000F_01C0E8E9.490719C0--