Importing topic maps with QuaaxTMIO
07.11.2010Last week, version 0.5.4 of the QuaaxTM PHP Topic Maps engine was released which, finally, brought XTM 2.1 read/write support via the QuaaxTMIO library. QuaaxTM now provides a basic tool set of Topic Maps technologies enabling PHP developers to build subject centric applications on the LAMP stack.
An essential feature is the import of topic maps. Topic maps (TMDM instances) can be serialized to one of the various Topic Maps syntaxes such as XTM 1.0/2.0/2.1, CTM, LTM, AsTMa=, or JTM to allow data interchange. Let’s see how to import a publicly available topic map from Maiana using the QuaaxTMIO library; I choose Lutz Maicher‘s topic map about Donald Duck in XTM 2.1 for the following example.
QuaaxTM has to be set up like described in README (maybe you’d like to tun the PHPUnit tests afterwards). You’ll need three classes then which you have to require_once:
TopicMapSystemFactory.class.php(fromlib/phptmapi2.0/core)PHPTMAPITopicMapHandler.class.php(fromlib/quaaxtmio/src/in)XTM201TopicMapReader.class.php(fromlib/quaaxtmio/src/in)
First, get a TopicMapSystem:
$tmSystemFactory = TopicMapSystemFactory::newInstance();
// QuaaxTM specific feature
$tmSystemFactory->setFeature(
VocabularyUtils::QTM_FEATURE_AUTO_DUPL_REMOVAL, false
);
$tmSystem = $tmSystemFactory->newTopicMapSystem();
Import the topic map using the XTM 2.0/2.1 parser and a topic map handler:
$tmHandler = new PHPTMAPITopicMapHandler($tmSystem, 'http://localhost/topicmaps/1');
$reader = new XTM201TopicMapReader($tmHandler);
$reader->readFile(
'http://maiana.topicmapslab.de/u/lmaicher/tm/ducks/download.xtm'
);
Finally access the imported topic map via PHPTMAPI 2.0:
$tm = $tmSystem->getTopicMap('http://localhost/topicmaps/1');
$topics = $tm->getTopics();
echo count($topics);// 278