Using TEXT attribute (since 4.6) - Java

9 views
Skip to first unread message

DEX graphdb

unread,
Feb 14, 2013, 8:43:36 AM2/14/13
to dex...@googlegroups.com
Since 4.6 DEX is offering TEXT in a new interface for attributes that do not fit in a String. Previous versions dealt TEXT attributes inside Value.

Here is an example with Java using the new TEXT interface. Following the example from the Starting Guide, we would like to add storylines to each of the movies in the graph. For instance here we add a storyline to "Lost In Transalation" movie:

// Set the STORYLINE attribute for the Lost in Translation movie
   String storylinePart1 = "This could be part of the storyline, read from ";
   String storylinePart2 = "a text file to a simple char[].";
   TextStream tstrm = new TextStream(false);
       g.setAttributeText(mLostInTranslation, movieStorylineType, tstrm);
   char[] textBuffer = storylinePart1.toCharArray();
       tstrm.write(textBuffer, textBuffer.length);
   textBuffer = storylinePart2.toCharArray();
       tstrm.write(textBuffer, textBuffer.length);
       tstrm.close();

We are using Part1 and Part2 Strings in order to illustrate how the write works, but the most appropiate way would be to read that storyline from a file.

Take into account that with:

new TextStream(false);

we state that we want to write from the beginning instead of appending at the end.

Now we want to read the TEXT attribute, let's retrieve the storyline from "Lost In Translation":

// Get the STORYLINE attribute for the Lost in Translation movie
   char[] textBuffer = new char[1024];
   TextStream tstrm = g.getAttributeText(mLostInTranslation, movieStorylineType);
   int readed;
   String storyline = new String();
   do {
       readed = tstrm.read(textBuffer, textBuffer.length);
       storyline += new String(textBuffer, 0, readed);
   } while (readed > 0);
   tstrm.close();
   System.out.println("The TEXT attribute value: \""+ storyline+"\"");

More information in the reference manual here: http://sparsity-technologies.com/downloads/javadoc-java/com/sparsity/dex/gdb/TextStream.html

Ross

unread,
Mar 26, 2013, 8:20:04 AM3/26/13
to dex...@googlegroups.com
Thanks for this explanation.  I notice the text in the API docs still seems to show the old way, using Value:

"Use of TextStream for writing: (i) Create a TextStream instance and (ii) set a Value instance with this TextStream instance, then (iii) use this value to set the Text attribute of a node or edge instance. Once the set attribute has been done, (iii) perform as many Write operations as you need to the TextStream instance. Lastly, (iv) exeucte Close to flush and close the stream.

Use of TextStream for reading: (i) Get the text attribute of a node or edge instance and (ii) get the TextStream instance from the retrieved Value instance. Once you have the TextStream instance, you can execute Read operations to read from the stream. (iii) The end of the stream is reached when Read returns 0. Finally, (iv) execute Close to close stream resources."

dex...@gmail.com

unread,
Mar 26, 2013, 9:54:15 AM3/26/13
to
Hello Ross,

Thanks for noticing it!, we will correct it from the API docs and of course it will be updated in the next release. 

Let me add, that apart from the post in the google group, the Text attributes section from the API chapter of the User Manual also has the correct explanation for this: http://sparsity-technologies.com/dex_tutorials5?name=API .

Thanks again!
Reply all
Reply to author
Forward
0 new messages