/** * Constructor that accepts a File object as argument (XTM file). */ public SanityChecker(File file) throws MalformedURLException, IOException { this(ImportExportUtils.getReader(file).read()); }
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); }
private static void convert(String infile, String outfile, OptionsListener options) throws java.io.IOException, java.net.MalformedURLException { TopicMapReaderIF reader = ImportExportUtils.getReader(infile); if (options.rdfmap != null) { Map<String, Object> config = new HashMap<String, Object>(); config.put("mappingFile", new File(options.rdfmap)); config.put("mappingSyntax", getSyntax(options.rdfmap)); reader.setAdditionalProperties(config); } if (reader instanceof XTMTopicMapReader) ((XTMTopicMapReader) reader).setValidation(options.validate); TopicMapIF tm = reader.read(); DuplicateSuppressionUtils.removeDuplicates(tm); if (options.xtm) { if (options.encoding != null) new XTMTopicMapWriter(new File(outfile), options.encoding).write(tm); else new XTMTopicMapWriter(new File(outfile)).write(tm); } else ImportExportUtils.getWriter(new File(outfile), options.encoding).write(tm); }
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); } }
properties.put("mappingFile", new File(mappingFile)); reader.setAdditionalProperties(properties);
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; }
/** * Constructor that accepts a url as argument (XTM file). */ public SanityChecker(String url) throws MalformedURLException, IOException { this(ImportExportUtils.getReader(url).read()); }
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; }
@Override public Object construct() { TopicMapIF result = null; try { result = r.read(); } catch (IOException e) { dialog.setVisible(false); ErrorDialog.showError(vpanel, e.getMessage()); } return result; }
importer.importInto(tm);
protected static TopicMapIF merge(String stm1, String stm2) throws ConstraintViolationException, java.io.IOException { TopicMapIF source1 = ImportExportUtils.getReader(stm1).read(); TopicMapIF source2 = ImportExportUtils.getReader(stm2).read(); MergeUtils.mergeInto(source1, source2); return source1; }
@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; }
/** * Creates a schema from the given topic map which is read in fist. * * @param input filename of the input topic map. */ public OSLSchema createSchema(String input) throws IOException { TopicMapIF tm = ImportExportUtils.getReader(input).read(); return createSchema(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 static TopicMapIF merge(TopicMapIF target, String source) throws ConstraintViolationException, java.io.IOException { TopicMapIF sourcetm = ImportExportUtils.getReader(source).read(); MergeUtils.mergeInto(target, sourcetm); return target; }
@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(); }
private static void validate(String tmfile, String schemafile) throws java.io.IOException, SchemaViolationException, SchemaSyntaxException { log.info("Reading schema"); OSLSchemaReader sreader = new OSLSchemaReader(new File(schemafile)); SchemaIF schema = sreader.read(); SchemaValidatorIF validator = schema.getValidator(); validator.setValidationHandler(new TextValidationHandler()); log.info("Reading topic map"); TopicMapReaderIF tmreader = ImportExportUtils.getReader(tmfile); TopicMapIF tm = tmreader.read(); log.info("Validating topic map"); validator.validate(tm); log.info("Done validating"); }
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); }
throws IOException, java.net.MalformedURLException, InvalidQueryException { TopicMapIF tm = ImportExportUtils.getReader(tmfile).read();
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); }