org.wikipedia.miner.model
Class Category

java.lang.Object
  extended by org.wikipedia.miner.model.Page
      extended by org.wikipedia.miner.model.Category
All Implemented Interfaces:
java.lang.Comparable<Page>

public class Category
extends Page

This class represents categories in Wikipedia; the pages that exist to organize articles that discuss related topics. It is intended to contain all properties and methods that are relevant for a category, such as its pertinent statistics, the categories and articles it contains, and the categories it belongs to.

Author:
David Milne

Field Summary
 
Fields inherited from class org.wikipedia.miner.model.Page
ARTICLE, CATEGORY, DISAMBIGUATION, REDIRECT
 
Constructor Summary
Category(WikipediaDatabase database, int id)
          Initialises a newly created Category so that it represents the category given by id.
Category(WikipediaDatabase database, int id, java.lang.String title)
          Initialises a newly created Category so that it represents the page given by id and title.
Category(WikipediaDatabase database, java.lang.String title)
          Initialises a newly created Category so that it represents the category given by title.
 
Method Summary
 boolean contains(Article article)
          Returns true if the argument article is a child of this category, otherwise false
 int[] getChildArticleIds()
           
 SortedVector<Article> getChildArticles()
          Returns an ordered Vector of Articles that belong to this category.
 SortedVector<Category> getChildCategories()
          Returns a SortedVector of Categories that this category contains.
 int[] getChildCategoryIds()
           
 Article getEquivalentArticle()
          Returns the Article that relates to the same concept as this category.
 SortedVector<Category> getParentCategories()
          Returns a SortedVector of Categories that this category belongs to.
 int[] getParentCategoryIds()
           
static void main(java.lang.String[] args)
          Provides a demo of functionality available to Categories
 
Methods inherited from class org.wikipedia.miner.model.Page
compareTo, createPage, equals, getContent, getFirstParagraph, getFirstSentence, getGenerality, getId, getScope, getTitle, getTitleWithoutScope, getType, getWeight, setWeight, toString
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Category

public Category(WikipediaDatabase database,
                int id,
                java.lang.String title)
Initialises a newly created Category so that it represents the page given by id and title. This is the most efficient constructor as no database lookup is required.

Parameters:
database - an active WikipediaDatabase
id - the unique identifier of the category
title - the (case dependent) title of the category

Category

public Category(WikipediaDatabase database,
                int id)
         throws java.sql.SQLException
Initialises a newly created Category so that it represents the category given by id.

Parameters:
database - an active WikipediaDatabase
id - the unique identifier of the category
Throws:
java.sql.SQLException - if no page is defined for the id, or if it is not an article.

Category

public Category(WikipediaDatabase database,
                java.lang.String title)
         throws java.sql.SQLException
Initialises a newly created Category so that it represents the category given by title.

Parameters:
database - an active WikipediaDatabase
title - the (case dependent) title of the article
Throws:
java.sql.SQLException - if no article is defined for the title.
Method Detail

getEquivalentArticle

public Article getEquivalentArticle()
                             throws java.sql.SQLException
Returns the Article that relates to the same concept as this category. Note that many categories do not have equivalent articles; they to not relate to a single concept, and exist only to organize the articles and categories it contains. i.e Rugby Teams may have an equivalent article, but Rugby Teams by region is unlikely to. In this case null will be returned.

Returns:
the equivalent Article, or null
Throws:
java.sql.SQLException - if there is a problem with the database

getParentCategories

public SortedVector<Category> getParentCategories()
                                           throws java.sql.SQLException
Returns a SortedVector of Categories that this category belongs to. These are the categories that are linked to at the bottom of any Wikipedia category.

Returns:
a SortedVector of Categories
Throws:
java.sql.SQLException - if there is a problem with the Wikipedia database

getParentCategoryIds

public int[] getParentCategoryIds()
                           throws java.sql.SQLException
Returns:
a sorted array of category ids that this category belongs to.
Throws:
java.sql.SQLException - if there is a problem with the Wikipedia database.

getChildCategories

public SortedVector<Category> getChildCategories()
                                          throws java.sql.SQLException
Returns a SortedVector of Categories that this category contains. These are the categories that are presented in alphabetical lists in any Wikipedia category.

Returns:
a SortedVector of Categories
Throws:
java.sql.SQLException - if there is a problem with the Wikipedia database

getChildCategoryIds

public int[] getChildCategoryIds()
                          throws java.sql.SQLException
Returns:
a sorted array of category ids that this category belongs to.
Throws:
java.sql.SQLException - if there is a problem with the Wikipedia database.

contains

public boolean contains(Article article)
                 throws java.sql.SQLException
Returns true if the argument article is a child of this category, otherwise false

Parameters:
article - the article of interest
Returns:
true if the argument article is a child of this category, otherwise false
Throws:
java.sql.SQLException - if there is a problem with the Wikipedia database

getChildArticles

public SortedVector<Article> getChildArticles()
                                       throws java.sql.SQLException
Returns an ordered Vector of Articles that belong to this category.

Returns:
a Vector of Articles
Throws:
java.sql.SQLException - if there is a problem with the wikipedia database

getChildArticleIds

public int[] getChildArticleIds()
                         throws java.sql.SQLException
Returns:
a sorted array of article ids that belong to this category.
Throws:
java.sql.SQLException - if there is a problem with the Wikipedia database.

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Provides a demo of functionality available to Categories

Parameters:
args - an array of arguments for connecting to a wikipedia database: server and database names at a minimum, and optionally a username and password
Throws:
java.lang.Exception - if there is a problem with the wikipedia database.