How to build an hierarchy?
I want to analyze a piece of document and build an ontology from 开发者_JAVA百科it. There could be many characteristics of this document, and it could be a hierarchy.
What is the best programming method to build this hierarchy with unlimited height? A tree?
I am looking for a broad "way" of programming, not necessary code.
I'm not sure about best, but one approach I've used in the past is to define a simple object which includes a property which is a collection of the same type as itself - so you can basically chain objects together; think 'nested folders' (a folder may contain multiple child folders).
You can either use that approach as the basis of an object that contains the information you want to collect, or you could farm it out to a flat collection of more detailed objects which simply reference the objects that define the tree structure. The best approach will depend on what your trying to do.
Does that help? what language are you working in?
There are probably a pile of 'proper' design patterns for the problem you trying to solve too.
That is pretty broad. But yes, trees are good for hierarchies. They pretty much are hierarchies. Can't really comment further unless you're more specific about what you want to do.
If you're parsing a document, ANTLR might be of interest.
精彩评论