How to set Labels in Ratel UI


(Ami Pandat) #1

I have loaded JSON data in ratel and then I have run a query which only displays nodes. So, how to set label to each node?


(Michel Conrado) #2

That depends on what kind of label you’re talking about.

  "set": [
     {
       "uid": "0xd", #UID of the existing node.
       "label": ""
     }
  ]
}
  "set": [
     {
       "uid": "0xd", #UID of the existing node.
       "labelx": "true"
     }
  ]
}
  "set": [
     {
       "uid": "0xd", #UID of the existing node.
       "type": "message"
     }
  ]
}

(Ami Pandat) #3

I have loaded my dataset [in JSON format] by using bulk loader which contains 98k triples in the format,
{

"Subject": "MeasureData_Precipitation_4UT01_2004_8_8_19_30_00>",

"Predicate": "sensor-observation.owl#uom>",

"Object": "weather.owl#centimeters>"

},

{

"Subject": "Observation_WindDirection_4UT01_2004_8_8_9_35_00>",

"Predicate": "22-rdf-syntax-ns#type>",

"Object": "weather.owl#WindDirectionObservation>"

},

{

"Subject": "Observation_WindDirection_4UT01_2004_8_8_9_35_00>",

"Predicate": "sensor-observation.owl#observedProperty>",

"Object": "weather.owl#_WindDirection"

}

and so on…
So when I run a query after loading data by bulk loader it shows output

As we can see here there is no label; here I want to label each node by its subject name.
Also I want to create edges between subject and object…will it be possible?


(Michel Conrado) #4

Wait, is this a JSON representation of a RDF? This format is invalid for Dgraph. Works, but invalid.

This is because the format is wrong. Check the right format in docs.


(Ami Pandat) #5

I have converted my .csv file by using csv2json command as per given in docs.

$csv2json csvfile --out jsonfilename


(Michel Conrado) #6

I did this image to explaing a bit the JSON format.


(Michel Conrado) #7

hummm, I have to check this. Seems wrong.


(Michel Conrado) #8

Nope, the Docs are right. :confused:


(Ami Pandat) #9

But I have followed the steps given in docs.

This is how my csv looks like.


(Michel Conrado) #10

Okay, your CSV is a JSON representation of RDF format.

Like this:

You need to convert this. Or export to RDF. It’s already in RDF tho. But in a CSV file.


(Ami Pandat) #11

Can you suggest me how?
I didn’t find any such tool for direct conversion.
And after converting it to RDF …again I have to convert it to JSON right?


(Michel Conrado) #12

Try Export to a text file and if you have something like this:
<observation ...> <22-rdf-syntax...> <weatger...>
you’re good to go. So you just need to add a “.” dot in every Nquads lines and use it in a mutation.

BTW, I recomend that you clean a bit this file. Maybe it will not be a problem, but if it gives you’ll have to clean it up a bit. Like Objects need to be in quotes “obj”. And some RDF types can be not supported. But just test it first. see the types https://docs.dgraph.io/mutations/#language-and-rdf-types

Don’t need. Use the RDF.


(Ami Pandat) #13

No., I don’t have all strings like this. And I have 98k triples. So, to set it like that is a crucial task I guess.:roll_eyes::roll_eyes:


(Michel Conrado) #14

Didn’t get it. You can.

I think you didn’t undestood what I said.

So, I did this: Exported to “.tsv”:

And you just need to do this:

And you’re good to go.


(Ami Pandat) #15

Ooh Okay…okay
Got it!
Then by which extension should I save it?.. I mean will it be .rdf file?
Because in bulk loader I have to pass .rdf file…so…


(Michel Conrado) #16

Don’t need. You gonna use Ratel right? can be text. If you gonna use Liveload or Bulk, can be any format tho. But if so, use *.rdf


(Ami Pandat) #17

okay
Then label will create automatically…right?


(Michel Conrado) #18

Sorry, I still do not understand which Label you’re talking about. The “kind” or the naming representation in Ratel UI?


(Ami Pandat) #19

This snapshot is the result of data given in docs[tour.dgraph.io]

Here each node and edge contains a label for ex. nodes have names like Michael, Amit etc.[with green and blue font …just below the nodes],edge is containing f on it.

So I want that type of label on my nodes I mean by using my dataset.


(Michel Conrado) #20

Ah, okay. This is “the naming representation in Ratel UI”. So this takes in consideration the predicate itself. I’m not sure what pattern it chooses to predict Ratel “labeling”, but it will certainly recognize one. If not, try using Alias.
e.g:

{
   q(func: ...){
     somepred
     name : someother_pred
   }
}

So using “name”, maybe Ratel will capture the values of “someotether_pred” as default.