comparison runner/FeatureExtractionManager.cpp @ 98:136d8496a4b8

Skip trying RDF parser if we have a filename ending in xml (we don't support RDF-XML and it just confuses the Turtle parser)
author Chris Cannam
date Wed, 01 Oct 2014 13:35:35 +0100
parents 03b1d83fca29
children 010fbf2a3fba
comparison
equal deleted inserted replaced
95:03b1d83fca29 98:136d8496a4b8
371 } 371 }
372 372
373 bool FeatureExtractionManager::addFeatureExtractorFromFile 373 bool FeatureExtractionManager::addFeatureExtractorFromFile
374 (QString transformXmlFile, const vector<FeatureWriter*> &writers) 374 (QString transformXmlFile, const vector<FeatureWriter*> &writers)
375 { 375 {
376 RDFTransformFactory factory 376 bool tryRdf = true;
377 (QUrl::fromLocalFile(QFileInfo(transformXmlFile).absoluteFilePath()) 377
378 .toString()); 378 if (transformXmlFile.endsWith(".xml") || transformXmlFile.endsWith(".XML")) {
379 ProgressPrinter printer("Parsing transforms RDF file"); 379 // We don't support RDF-XML (and nor does the underlying
380 std::vector<Transform> transforms = factory.getTransforms(&printer); 380 // parser library) so skip the RDF parse if the filename
381 if (!factory.isOK()) { 381 // suggests XML, to avoid puking out a load of errors from
382 cerr << "WARNING: FeatureExtractionManager::addFeatureExtractorFromFile: Failed to parse transforms file: " << factory.getErrorString().toStdString() << endl; 382 // feeding XML to a Turtle parser
383 if (factory.isRDF()) { 383 tryRdf = false;
384 return false; // no point trying it as XML 384 }
385 } 385
386 } 386 if (tryRdf) {
387 if (!transforms.empty()) { 387 RDFTransformFactory factory
388 bool success = true; 388 (QUrl::fromLocalFile(QFileInfo(transformXmlFile).absoluteFilePath())
389 for (int i = 0; i < (int)transforms.size(); ++i) { 389 .toString());
390 if (!addFeatureExtractor(transforms[i], writers)) { 390 ProgressPrinter printer("Parsing transforms RDF file");
391 success = false; 391 std::vector<Transform> transforms = factory.getTransforms(&printer);
392 } 392 if (!factory.isOK()) {
393 } 393 cerr << "WARNING: FeatureExtractionManager::addFeatureExtractorFromFile: Failed to parse transforms file: " << factory.getErrorString().toStdString() << endl;
394 return success; 394 if (factory.isRDF()) {
395 return false; // no point trying it as XML
396 }
397 }
398 if (!transforms.empty()) {
399 bool success = true;
400 for (int i = 0; i < (int)transforms.size(); ++i) {
401 if (!addFeatureExtractor(transforms[i], writers)) {
402 success = false;
403 }
404 }
405 return success;
406 }
395 } 407 }
396 408
397 QFile file(transformXmlFile); 409 QFile file(transformXmlFile);
398 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { 410 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
399 cerr << "ERROR: Failed to open transform XML file \"" 411 cerr << "ERROR: Failed to open transform XML file \""