T
T
Think With Your Head2016-03-14 20:12:03
Programming
Think With Your Head, 2016-03-14 20:12:03

What algorithm should be used to parse these product categories and turn them into a tree structure?

I’ve been suffering for an hour, I just can’t figure out how to turn this structure into a normal working view

<item>
    <ID>
    </ID>
    <name>
    </name>
    <about>
    </about>
    <price>
    </price>
    <manufacture>
    </manufacture>

    <category2>
    </category2>

    <category1>
    </category1>

    <category0>
    </category0>
  </item>
    <item>
    <ID>
    </ID>
    <name>
    </name>
    <about>
    </about>
    <price>
    </price>
    <manufacture>
    </manufacture>

    <category2>
    </category2>

    <category1>
    </category1>

    <category0>
    </category0>
  </item>
......

The problem is that the product categories are not nested and do not have IDs, how to turn this into a tree without a clue - the whole brain is broken. The category content itself assumes a tree of the form
category0
----category1
--------category2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene 222, 2016-03-14
@Vyad

prefix tree. Split by category. Can be done with hashes.
The result is your tree.
Prefix tree: https://en.wikipedia.org/wiki/Trie
--------
Pseudocode

Для каждого <item>:
  Взять категории по порядку. [cat1,cat2,cat3]
  Уложить этот путь в trie. 
  В качестве листа, указать все остальные<не категории> элементы item
Готово

-------
If you have duplicate characterizing attributes for elements For example: not
ID name but pbbpp. Then use Nedelman Wunsch's line alignment algorithm with backtracking. Tokinize by characterizing elements.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question