哪种数据结构来存储共同作者?
我有一个作者列表,其中包含书名和出版年份,例如:
Brian Goetz、Tim Peierls、Joshua Bloch、Joseph Bowbeer、David Holmes、Doug Lea:Java 并发实践,2006 年
Ken Arnold、James Gosling 和 David Holmes:Java 编程语言,2005 年
...
我想知道哪种数据结构最适合存储有关共同作者、他们一起撰写的书籍以及出版年份的信息。
我想稍后使用这些信息来绘制图表(在 JUNG 中,我使用的是 java),其中每个作者将是节点,边缘将是他们共同创作的每本书。每年都会绘制单独的图表。我正在考虑使用多重映射:
Map<Year, Map<Author, List<Map<Co-author, Title>>>>
但这也许过于复杂?
预先感谢您的任何帮助。
I have a list of authors with title of the book and the year of publication, for example:
Brian Goetz, Tim Peierls, Joshua Bloch, Joseph Bowbeer, David Holmes, Doug Lea: Java Concurrency in Practice, 2006
Ken Arnold, James Gosling and David Holmes: Java Programming Language, 2005
...
I was wondering what data structure would be best to store information about co-authors, book they have written together and year of publication.
I would like to later use this information to draw graphs (in JUNG, I'm using java), where each author would be node and the edge would be each book they co-authored. Separate graph would be drawn for every year. I was thinking of using multimap:
Map<Year, Map<Author, List<Map<Co-author, Title>>>>
but maybe this is overcomplicated?
Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将一组作者和标题放入一个名为“Book”的对象中怎么样?这样,您的数据结构就可以是简单的
。图形绘制算法可以像这样工作:
drawEdge
方法将首先检查两个作者是否已经绘制了相应的节点(例如,使用包含已经绘制的作者的集合)节点,或者可能是作者 => 节点图)并绘制所需的节点,然后在它们之间绘制一条边。How about placing a set of authors and title in an object, named, for example, 'Book'? That way, your data structures could be simply
The graph-drawing algorithm could work like this:
drawEdge
method would first check if both authors have corresponding nodes already drawn (for example using a set containing authors with already drawn nodes, or perhaps an Author => Node map) and draw needed nodes, and then draw an edge between them.只需用它创建一个 JUNG 图即可; JUNG 将处理数据结构。也就是说,节点将是作者,边缘将是合著者关系(其中包含有关作品的信息)。
也就是说,在过去使用过共同作者图时,您可能需要考虑将共同作者关系更自然地表示为二部图(作者与作品)或超图。这样您就不需要多次冗余地表示工作。
Just create a JUNG graph out of it; JUNG will handle the data structures. That is, nodes will be Authors and edges will be Coauthor relationships (which would consist of information about the work).
That said, having worked with co-authorship graphs in the past, you may want to consider the more natural representation of coauthorship as either a bipartite graph (Authors vs Works) or a hypergraph. That way you don't need to redundantly represent the work multiple times.
我认为这样构造数据是一个坏主意,为什么不使用多态性概念呢?
为什么不创建
Class Book
,包含出版年份、名称等内容。然后创建另一个实体,例如
Class Author
,并在两个 Book 之间构建将包含List
coAuthors 和 Author< /strong> 可以包含List
I Think this is a bad idea to structure your data like that, why not use the polymorphism concept?
Why not creating
Class Book
, containing stuff like year of publication, name etc..Than create another entity such as
Class Author
, and construct between the two Book will containList<Author>
coAuthors , and Author can containList<Book>