使用类别和类别链接表查找维基百科类别的子类别 [英] Finding subcategories of a wikipedia category using category and categorylinks table

查看:107
本文介绍了使用类别和类别链接表查找维基百科类别的子类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从mediawiki下载了category和categorylinks表sql.gz文件,并生成了所需的表:

I downloaded the category and categorylinks table sql.gz files from mediawiki and generated the required tables:

类别和类别链接

表的手册: 类别链接 类别

请考虑以下类别页面: NoSQL 该页面的父类别是数据库和数据库管理".我如何从两个表中获取此信息? 类别表的手册中说明了以下内容,但我无法获取该信息: "

Consider the following category page of: NoSQL The parent category of this page is Database and Database management. How could I get this information from the two tables? The manual for category table says the following but I am unable to get that information: "

注意:页面和子类别存储在类别链接中 表."

Note: The pages and sub-categories are stored in the categorylinks table."

推荐答案

仅类别就没有层次感.使分类工作的是分类页面.因此,您还必须从page表中获取page_id才能解决此关系.

Categories alone have no hierachy. It’s the category pages that make the subcategorization work. So you will also have to get the page_id from the page table to be able to resolve this relation.

它基本上是这样的:

  1. 类别的cat_title是页面标题.
  2. 在页表中找到page_title,获取page_id
  3. 使用page_id获取cl_from
  4. 中的类别链接
  5. cl_to
  6. 获取父类别标题
  7. 从2开始重复
  1. Category’s cat_title is a page title.
  2. Find that page_title in the page table, get the page_id
  3. Use the page_id to get the category link in cl_from
  4. Get the parent category title from cl_to
  5. Repeat from 2

这篇关于使用类别和类别链接表查找维基百科类别的子类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆