public void upgrade() { // produce LTM fragment StringBuilder sb = new StringBuilder(); sb.append("#PREFIX on @\"http://psi.ontopia.net/ontology/\"\n"); sb.append("#PREFIX xtm @\"http://www.topicmaps.org/xtm/1.0/core.xtm#\"\n"); sb.append("#PREFIX tech @\"http://www.techquila.com/psi/hierarchy/#\"\n"); sb.append("#PREFIX xsd @\"http://www.w3.org/2001/XMLSchema#\"\n"); importLTM(sb); // import ltm fragment Reader reader = new StringReader(sb.toString()); TopicMapReaderIF importer = new LTMTopicMapReader(reader, URILocator.create("http://psi.ontopia.net/ontology/")); try { importer.importInto(topicmap); } catch (IOException e1) { throw new OntopiaRuntimeException(e1); } // transform topic map try { transform(); } catch (InvalidQueryException e) { throw new OntopiaRuntimeException(e); } }
protected static void canonicalize(String stm, String ctm, boolean readall) throws IOException, MalformedURLException { TopicMapIF source; try { if (readall) { TopicMapReaderIF importer = ImportExportUtils.getReader(stm); source = new InMemoryTopicMapStore().getTopicMap(); importer.importInto(source); } else { TopicMapReaderIF reader = ImportExportUtils.getReader(stm); source = reader.read(); } DuplicateSuppressionUtils.removeDuplicates(source); } catch (InvalidTopicMapException e) { System.err.println("ERROR reading file: " + e.getMessage()); return; } new CanonicalXTMWriter(new File(ctm)).write(source); }
protected long importTopicMap(URL filename) throws IOException { // import sample topic map TopicMapStoreIF store = new RDBMSTopicMapStore(); // don't use storage TopicMapReaderIF importer = ImportExportUtils.getReader(filename.toString()); importer.importInto(store.getTopicMap()); long topicmap_id = Long.parseLong(store.getTopicMap().getObjectId().substring(1)); store.commit(); store.close(); return topicmap_id; }
protected long importTopicMap(String filename) throws IOException { // import sample topic map TopicMapStoreIF store = new RDBMSTopicMapStore(); // don't use storage TopicMapReaderIF importer = ImportExportUtils.getReader(filename); importer.importInto(store.getTopicMap()); long topicmap_id = Long.parseLong(store.getTopicMap().getObjectId().substring(1)); store.commit(); store.close(); return topicmap_id; }
importer.importInto(tm);
@Override protected TopicMapIF loadTopicMap(boolean readonly) throws IOException { // create topic map importer TopicMapReaderIF reader = getImporter(); // create empty topic map InMemoryTopicMapStore store = new InMemoryTopicMapStore(); if (base_address != null) store.setBaseAddress(base_address); TopicMapIF tm = store.getTopicMap(); // import file into topic map reader.importInto(tm); // suppress duplicates if (getDuplicateSuppression()) DuplicateSuppressionUtils.removeDuplicates(tm); if (maintainFulltextIndexes) { for (FulltextImplementationIF ft : ftmanagers) { ft.storeOpened(store); } } return tm; }
@Test public void testImportTopicMaps() throws IOException { // Create empty store InMemoryTopicMapStore store = new InMemoryTopicMapStore(); TopicMapIF tm = store.getTopicMap(); // Import first XTM file String file1 = TestFileUtils.getTestInputFile(testdataDirectory, "in", "latin1.xtm"); TopicMapReaderIF importer1 = new XTMTopicMapReader(TestFileUtils.getTestInputURL(file1)); importer1.importInto(tm); // Import second XTM file String file2 = TestFileUtils.getTestInputFile(testdataDirectory, "in", "mergeloop.xtm"); TopicMapReaderIF importer2 = new XTMTopicMapReader(TestFileUtils.getTestInputURL(file2)); importer2.importInto(tm); // Check the result Assert.assertTrue("topic map has't got exactly four topics: " + tm.getTopics().size(), tm.getTopics().size() == 4); }
protected void load(String filename, boolean fulltext) throws IOException { // IMPORTANT: This method is being overloaded by the RDBMS // implementation to provide the right object implementations. URL file = TestFileUtils.getTestInputURL(testdataDirectory, filename); InMemoryTopicMapStore store = new InMemoryTopicMapStore(); topicmap = store.getTopicMap(); builder = store.getTopicMap().getBuilder(); base = new URILocator(file); TopicMapReaderIF importer = ImportExportUtils.getReader(file.toString()); if (importer instanceof XTMTopicMapReader) ((XTMTopicMapReader) importer).setValidation(false); importer.importInto(topicmap); if (fulltext) { new DummyFulltextSearcherIF(store); } processor = new QueryProcessor(topicmap, base); }
@Test public void testTopicMapDeletion() throws Exception { String name = TestFileUtils.getTestInputFile(testdataDirectory, "in", filename); TopicMapIF tm = makeTopicMap(); TopicMapReaderIF importer = ImportExportUtils.getReader(name); if (name.endsWith(".xtm")) ((XTMTopicMapReader) importer).setValidation(false); try { importer.importInto(tm); } catch (OntopiaRuntimeException ore) { // catch and re-throw to add filename to message throw new OntopiaRuntimeException(ore.getMessage() + " in " + name, ore); } clearTopicMap(tm); tm.getStore().close(); }
public static void load(AbstractQueryTest test, String filename) throws IOException { URL file = TestFileUtils.getTestInputURL(testdataDirectory, filename); checkDatabasePresence(); RDBMSTopicMapStore store = new RDBMSTopicMapStore(); test.topicmap = store.getTopicMap(); test.builder = store.getTopicMap().getBuilder(); test.base = new URILocator(file); store.setBaseAddress(test.base); TopicMapReaderIF importer = ImportExportUtils.getReader(file.toString()); if (importer instanceof XTMTopicMapReader) ((XTMTopicMapReader) importer).setValidation(false); importer.importInto(test.topicmap); // NOTE: Query processor must have base set, because of the way // the test suite looks up source locators. //! test.processor = new QueryProcessor(test.topicmap, test.base); test.processor = QueryUtils.createQueryProcessor(test.topicmap, test.base); }
@Override public void setUp() throws Exception { // get a new topic map object from the factory. factory = getFactory(); topicmapRef = factory.makeTopicMapReference(); listener = new TesterListener(); TopicMapEvents.addTopicListener(topicmapRef, listener); // load topic map topicmap = topicmapRef.createStore(false).getTopicMap(); ImportExportUtils.getReader(TestFileUtils.getTestInputFile("various", "bart.ltm")).importInto(topicmap); topicmap.getStore().commit(); // get the builder of that topic map. builder = topicmap.getBuilder(); // get test topic bart = topicmap.getTopicBySubjectIdentifier(URILocator.create("test:bart")); }
@Override public void setUp() throws Exception { // get a new topic map object from the factory. factory = getFactory(); try { topicmapRef = factory.makeTopicMapReference(); listener = new EventListener(); TopicMapEvents.addTopicListener(topicmapRef, listener); // load topic map topicmap = topicmapRef.createStore(false).getTopicMap(); ImportExportUtils.getReader(TestFileUtils.getTestInputFile("various", "alumni.xtm")).importInto(topicmap); topicmap.getStore().commit(); // get the builder of that topic map. builder = topicmap.getBuilder(); // clean up the listener listener.reset(); } catch (java.io.IOException e) { throw new OntopiaRuntimeException(e); } }
TopicMapIF tm = store.getTopicMap(); TopicMapReaderIF importer = new XTMTopicMapReader(file); importer.importInto(tm); long topicmap_id = Long.parseLong(tm.getObjectId().substring(1)); store.commit();