哪种数据结构来存储共同作者?

发布于 2024-12-12 12:22:56 字数 575 浏览 0 评论 0原文

我有一个作者列表,其中包含书名和出版年份,例如:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我的奇迹 2024-12-19 12:22:56

将一组作者和标题放入一个名为“Book”的对象中怎么样?这样,您的数据结构就可以是简单的

class Book {
    List<Author> authors;
    Title title;
}

Map<Year, Set<Book>> booksInYears

。图形绘制算法可以像这样工作:

for (Book book : booksInYears.get(aYear)) 
    for (Author author1 : book.authors) 
        for (Author author2 : book.authors) 
            if (author1 != author2) 
                drawEdge(author1, author2, book.title);

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

class Book {
    List<Author> authors;
    Title title;
}

Map<Year, Set<Book>> booksInYears

The graph-drawing algorithm could work like this:

for (Book book : booksInYears.get(aYear)) 
    for (Author author1 : book.authors) 
        for (Author author2 : book.authors) 
            if (author1 != author2) 
                drawEdge(author1, author2, book.title);

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.

庆幸我还是我 2024-12-19 12:22:56

只需用它创建一个 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.

愁以何悠 2024-12-19 12:22:56

我认为这样构造数据是一个坏主意,为什么不使用多态性概念呢?

为什么不创建 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 contain List<Author> coAuthors , and Author can contain List<Book>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文