How can implement a nested hierarchical structure in Solidity? - ethereum

I need a piece of solidity code for the below scenario:
I want to create a nested hierarchical structure for the menu structure. But I have no idea.
Suppose my structure is like this
Product -> Mobile -> Samsung -> A50
First, when I want to insert A50, I have to be able to assign Product -> Mobile -> Samsung as Parent to A50
Second, when I searched for A50, I have to be able to fetch A50 parents too
Please help me to solve it.
Thanks

Related

Prolog csv flight data analysis

I'm working on expert system for flight data analysis.
the flight is a csv file. i would like to:
save each flight file( Aircraft number, Motor number and flight date)
define limitations of parameteres (motor and aircraft) in the Knowledge base:
for example T4(temperature before turbine) shouldn't exceed 650 over 30s.
save the report file as pdf or html
the problem is that to analyse the file you should make loops row by row in order to detect anomalies.
So, how can i do it with prolog? do you any suggestions?
You don't say what implementation you're using. I'm guessing SWI-Prolog.
You can write csv files using csv_write_file or csv//1,2
http://www.swi-prolog.org/pldoc/doc_for?object=csv//1
based on OP's feedback:
suppose you have some facts:
engine_temp(Time, Temp).
you could just get a list of them with findall
findall(Time-Temp, engine_temp(Time, Temp), List)
This binds List to pairs of form Time-Temp.
To generate HTML, using the SWI-Prolog library
:- use_module(library(http/html_write)).
:- http_handler('/temps', temp_hdlr, []).
temp_hdlr(_Request) :-
reply_html_page(title('engine temps'),
\temp_list
).
temp_list -->
{ findall(Time-Temp, engine_temp(Time, Temp), List) },
html(ul(\list_body(List))).
list_body([]) --> [].
list_body([Time-Temp | Rest]) -->
html(tr([td(Time), td(Temp)])),
list_body(Rest).
Hope a) that works, I'm away from dev machine, and b) the html generation boiler plate doesn't look too scary.
Hope that helps.

play scalaJson how to retrieve record when querying for value

So I am having a couple problems with Play's scalaJSON. First being that I am somehow not able to make my keys anything other than strings. I have defined a a JSONWrites converter as follows:
implicit val musics = new Writes[Question] {
def writes(question:Question) = Json.obj(
"questionID" -> question.questionID,
"questionText" -> question.questionText,
"responseURI" -> question.responseURI,
"constraints: min,max,Optional" -> Json.arr(question.minResponse, question.maxResponse, question.optionalQ),
"responseDataType" -> question.responseDataType
)
}
my model case class for question:
case class Question (questionID:Int,
questionText:String,
responseURI:String,
minResponse:Option[Int],
maxResponse:Option[Int],
optionalQ:Boolean,
responseDataType:String)
When desigining my REST API in play, I wanted to access the specific question of this survey app with a url such as /questionBlock/questionID
I tried to simply make the question.questionID the parent key and nest the rest of the JSON as the value to this key, but it would not allow me to do this, saying expected String actual Int
the actual JSON rendered out looks like this:
[{"questionID":0,"questionText":"What is your favorite musical artist?",
"responseURI":"/notDoneYet","constraints: min,max,Optional":[1,1,false],
"responseDataType":"String"},{"questionID":1,"questionText":"What is your favorite music genre?",
"responseURI":"/notDoneYet","constraints: min,max,Optional":[1,1,false],"responseDataType":"String"}]
But using this I cannot seem to figure out how to return the entire field where questionID equals 1 or 2 etc. I have used the 0th, 1st, etc element of the array but that is not the ideal approach for me, since question Ids may not always start at 0 for a particular sequence of questions.
Basically, I want to be able to show an entire record for one question when I provide the value of questionID. In Javascript I would have made the outermost key this questionID value, but I am unable to figure out how to do this using scalaJson. If there is an alternative way to accomplish this, I am open to suggestions.

Traverse a DAG (Directed Acyclic Graph) from specified node to create a tree view

I am putting together a parts database using the method below for directed acyclic graphs.
http://www.codeproject.com/Articles/22824/A-Model-to-Represent-Directed-Acyclic-Graphs-DAG-o
I am able to build my data set using the SQL queries from that page which I have converted to MySQL.
Previously I have used the nested sets model although we found that deletions became a problem.
I am unable to find any information on how to traverse the tree using this model. I simply need to be able to create a html tree to show the descendants from a selected parent node and identify leaf nodes (will be using jstree).
I can post the code from the nested sets model if that helps. I don't need any help with the html it is the SQL I am stuck with.
Does anyone have any idea where I can find information on the query I need.
EDIT:
Following on from the commments I'd like to adapt to something more closely linked to Bill Karwins closure model. http://www.slideshare.net/billkarwin/models-for-hierarchical-data
I notice however that on slides 49-50 which is where I want to select the descendants of a node that the output doesn't seem to provide enough to draw a simple tree. Previously with the nested sets model I was able to get a similar output that would traverse left to right, top to bottom. I'll try to explain.
Item | Depth
1 | 0
2 | 0
3 | 1
6 | 2
7 | 0
9 | 1
This allowed me to draw a tree as the SQL listed the order of descendants in a more manipulatable way. I believe it created "depth" by using a COUNT of subtrees and I will dig out the query if it would be useful here.
Thanks again for all your help.

Graphs - find common data

I've just started to read upon graph-teory and data structures.
I'm building an example application which should be able to find the xpath for the most common links. Imagine a Google serp, my application should be able to find the xpath for all links pointing to a result.
Imagine that theese xpaths were found:
/html/body/h2/a
/html/body/p/a
/html/body/p/strong/a
/html/body/p/strong/a
/html/body/p/strong/a
/html/body/div[#class=footer]/span[#id=copyright]/a
From these xpats, i've thought of a graph like this (i might be completely lost here):
html
|
body
h2 - p - div[#class=footer]
| | |
a (1) a - strong span[#id=copyright]
| |
a (3) a (1)
Is this the best approach to this problem?
What would be the best way (data structure) to store this in memory? The language does not mather. We can see that we have 3 links matching the path html -> body -> p -> strong -> a.
As I said, i'm totally new to this so please forgive me if I thought of this completely wrong.
EDIT: I may be looking for the trie data structure?
Don't worry about tries yet. Just construct a tree using standard graph representation (node = {value, count, parent} while immediately collapsing same branches and incrementing the counter. Then, sort all the leaves by count in descending order and traverse from each leaf upwards to get a path.

How to display a tree of objects in a JTree?

Imagine a collection of objects such as World, Country, Region and City. World contains a list of Country objects, Country contains a list of Region objects etc.
I would like to represent this structure in a JTree and be able to add, remove and move objects around the tree.
Can I easily create a TableModel from this structure? World would be the root object and I would need to perform some object-specific rendering.
Any one know of an appropriate tutorial that goes beyond building a tree from simple text nodes?
You might start with the examples mentioned in How to Use Trees. You may need profile your code if the intended number of leaf nodes is large. You may want to consider a map as an alternate interface for the uppermost levels. See also the three-part series of articles starting with Creating TreeTables in Swing.
Addendum: Part three in the series cited includes an example TreeTableModelAdapter.
$ ls -1 src/bookmarks/
AbstractTreeTableModel.java
Bookmarks.java
BookmarksModel.java
DynamicTreeTableModel.java
JTreeTable.java
TreeTableExample3.java
TreeTableModel.java
TreeTableModelAdapter.java