/// <summary> /// Parse the contents of <paramref name="data"/> as an N3 file /// </summary> /// <param name="data">The data stream to parse</param> /// <param name="sink">The target for the parsed RDF statements</param> /// <param name="defaultGraphUri">The default graph URI to assign to each of the parsed statements</param> public void Parse(Stream data, ITripleSink sink, string defaultGraphUri) { _sink = sink; _graphUri = defaultGraphUri; _bnodes = new Dictionary <string, string>(); var sr = new StreamReader(data); int lineNumber = 1; string line = sr.ReadLine(); try { while (line != null) { ParseLine(lineNumber, line); line = sr.ReadLine(); lineNumber++; } } catch (TripleSinkException tse) { throw tse.InnerException; } catch (RdfParserException) { // Rethrow parser exceptions without wrapping them. throw; } catch (Exception ex) { throw new RdfParserException("Error parsing NTriples stream", ex); } }
/// <summary> /// Parse from a text reader /// </summary> /// <param name="reader">The reader providing the data to be parsed</param> /// <param name="sink">The target for the parsed RDF statements</param> /// <param name="defaultGraphUri">The default graph URI to assign to each of the parsed statements</param> public void Parse(TextReader reader, ITripleSink sink, string defaultGraphUri) { _sink = sink; _graphUri = defaultGraphUri; _bnodes = new Dictionary <string, string>(); string line = reader.ReadLine(); int lineNumber = 1; while (line != null) { try { ParseLine(lineNumber, line); } catch (TripleSinkException tse) { throw tse.InnerException; } catch (RdfParserException) { throw; } catch (Exception ex) { throw new RdfParserException(lineNumber, "Error parsing NTriples stream", ex); } line = reader.ReadLine(); lineNumber++; } }
/// <summary> /// Parse from a text reader /// </summary> /// <param name="reader">The reader providing the data to be parsed</param> /// <param name="sink">The target for the parsed RDF statements</param> /// <param name="defaultGraphUri">The default graph URI to assign to each of the parsed statements</param> public void Parse(TextReader reader, ITripleSink sink, string defaultGraphUri) { _sink = sink; _graphUri = defaultGraphUri; _bnodes = new Dictionary<string, string>(); string line = reader.ReadLine(); int lineNumber = 1; while (line != null) { try { ParseLine(lineNumber, line); } catch(TripleSinkException tse) { throw tse.InnerException; } catch(RdfParserException) { throw; } catch (Exception ex) { throw new RdfParserException(lineNumber, "Error parsing NTriples stream", ex); } line = reader.ReadLine(); lineNumber++; } }
/// <summary> /// Parse the contents of <paramref name="data"/> as an N3 file /// </summary> /// <param name="data">The data stream to parse</param> /// <param name="sink">The target for the parsed RDF statements</param> /// <param name="defaultGraphUri">The default graph URI to assign to each of the parsed statements</param> public void Parse(Stream data, ITripleSink sink, string defaultGraphUri) { _sink = sink; _graphUri = defaultGraphUri; _bnodes = new Dictionary<string, string>(); var sr = new StreamReader(data); int lineNumber = 1; string line = sr.ReadLine(); try { while (line != null) { ParseLine(lineNumber, line); line = sr.ReadLine(); lineNumber++; } } catch (TripleSinkException tse) { throw tse.InnerException; } catch (RdfParserException) { // Rethrow parser exceptions without wrapping them. throw; } catch (Exception ex) { throw new RdfParserException("Error parsing NTriples stream", ex); } }
public override void Run() { try { Logging.LogInfo("Import job being run on file " + _contentFileName); StoreWorker.TransactionLog.LogStartTransaction(this); var parser = GetParser(_contentFileName); var storeDirectory = StoreWorker.WriteStore.DirectoryPath; var filePath = Path.Combine(storeDirectory, ".." + Path.DirectorySeparatorChar + "import" + Path.DirectorySeparatorChar + _contentFileName); var profiler = new BrightstarProfiler("Import " + _contentFileName); // TODO : Conditionally create this if profiling is enabled Logging.LogDebug("Import file path calculated as '{0}'", filePath); if (!File.Exists(filePath)) { ErrorMessage = String.Format("Cannot find file {0} in import directory", _contentFileName); throw new FileNotFoundException(ErrorMessage); } using (_fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { _importTripleSink = new StoreTripleSink(StoreWorker.WriteStore, JobId, Configuration.TransactionFlushTripleCount, profiler:profiler); parser.Parse(_fileStream, this, _graphUri); } StoreWorker.WriteStore.Commit(JobId, profiler); StoreWorker.InvalidateReadStore(); Logging.LogInfo("Import job completed successfully for " + _contentFileName); if (profiler != null) { Logging.LogInfo(profiler.GetLogString()); } StoreWorker.TransactionLog.LogEndSuccessfulTransaction(this); } catch (RdfParserException parserException) { ErrorMessage = parserException.Message; ExceptionDetail = new ExceptionDetail(parserException); Logging.LogInfo("Parser error processing import job on file " + _contentFileName + ". " + parserException.Message); throw; } catch (Exception ex) { ErrorMessage = "Error importing file " + _contentFileName + ". " + ex.Message; StoreWorker.TransactionLog.LogEndFailedTransaction(this); Logging.LogInfo("Error processing import job on file " + _contentFileName + ". Error Message: " + ex.Message + " Stack trace: " + ex.StackTrace); throw; } }
public override void Run() { try { Logging.LogInfo("Import job being run on file " + _contentFileName); StoreWorker.TransactionLog.LogStartTransaction(this); var parser = GetParser(_contentFileName); var storeDirectory = StoreWorker.WriteStore.DirectoryPath; var filePath = Path.Combine(storeDirectory, ".." + Path.DirectorySeparatorChar + "import" + Path.DirectorySeparatorChar + _contentFileName); var profiler = new BrightstarProfiler("Import " + _contentFileName); // TODO : Conditionally create this if profiling is enabled Logging.LogDebug("Import file path calculated as '{0}'", filePath); if (!File.Exists(filePath)) { ErrorMessage = String.Format("Cannot find file {0} in import directory", _contentFileName); throw new FileNotFoundException(ErrorMessage); } using (_fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { _importTripleSink = new StoreTripleSink(StoreWorker.WriteStore, JobId, Configuration.TransactionFlushTripleCount, profiler: profiler); parser.Parse(_fileStream, this, _graphUri); } StoreWorker.WriteStore.Commit(JobId, profiler); StoreWorker.InvalidateReadStore(); Logging.LogInfo("Import job completed successfully for " + _contentFileName); if (profiler != null) { Logging.LogInfo(profiler.GetLogString()); } StoreWorker.TransactionLog.LogEndSuccessfulTransaction(this); } catch (RdfParserException parserException) { ErrorMessage = parserException.Message; ExceptionDetail = new ExceptionDetail(parserException); Logging.LogInfo("Parser error processing import job on file " + _contentFileName + ". " + parserException.Message); throw; } catch (Exception ex) { ErrorMessage = "Error importing file " + _contentFileName + ". " + ex.Message; StoreWorker.TransactionLog.LogEndFailedTransaction(this); Logging.LogInfo("Error processing import job on file " + _contentFileName + ". Error Message: " + ex.Message + " Stack trace: " + ex.StackTrace); throw; } }
/// <summary> /// Parse the contents of <paramref name="data"/> as an RDF data stream /// </summary> /// <param name="data">The data stream to parse</param> /// <param name="sink">The target for the parsed RDF statements</param> /// <param name="defaultGraphUri">The default graph URI to assign to each of the parsed statements</param> public void Parse(Stream data, ITripleSink sink, string defaultGraphUri) { _sink = sink; _defaultGraphUri = defaultGraphUri; using ( #if !SILVERLIGHT && !PORTABLE var streamReader = _decompressStream ? new StreamReader(new GZipStream(data, CompressionMode.Decompress)) : new StreamReader(data)) #else var streamReader = new StreamReader(data)) #endif { _rdfReader.Load(this, streamReader); } }
public override void Run() { try { Logging.LogInfo("Import job being run on file " + _contentFileName); StoreWorker.TransactionLog.LogStartTransaction(this); var parser = GetParser(_contentFileName); var storeDirectory = StoreWorker.WriteStore.DirectoryPath; var importDirectory = Path.Combine(Path.GetDirectoryName(storeDirectory), "import"); var filePath = Path.Combine(importDirectory, _contentFileName); var profiler = Logging.IsProfilingEnabled ? new BrightstarProfiler("Import " + _contentFileName) : null; Logging.LogDebug("Import file path calculated as '{0}'", filePath); using (_fileStream = GetImportFileStream(filePath)) { _importTripleSink = new StoreTripleSink(StoreWorker.WriteStore, JobId, Configuration.TransactionFlushTripleCount, profiler: profiler); parser.Parse(_fileStream, this, _graphUri); } StoreWorker.WriteStore.Commit(JobId, profiler); StoreWorker.InvalidateReadStore(); Logging.LogInfo("Import job completed successfully for " + _contentFileName); if (profiler != null) { Logging.LogInfo(profiler.GetLogString()); } StoreWorker.TransactionLog.LogEndSuccessfulTransaction(this); } catch (RdfParserException parserException) { ErrorMessage = parserException.Message; ExceptionDetail = new ExceptionDetailObject(parserException); Logging.LogInfo("Parser error processing import job on file " + _contentFileName + ". " + parserException.Message); throw; } catch (Exception ex) { ErrorMessage = "Error importing file " + _contentFileName + ". " + ex.Message; StoreWorker.TransactionLog.LogEndFailedTransaction(this); Logging.LogInfo("Error processing import job on file " + _contentFileName + ". Error Message: " + ex.Message + " Stack trace: " + ex.StackTrace); throw; } }
public override void Run() { try { Logging.LogInfo("Import job being run on file " + _contentFileName); StoreWorker.TransactionLog.LogStartTransaction(this); var parser = GetParser(_contentFileName); var storeDirectory = StoreWorker.WriteStore.DirectoryPath; var importDirectory = Path.Combine(Path.GetDirectoryName(storeDirectory), "import"); var filePath = Path.Combine(importDirectory, _contentFileName); var profiler = Logging.IsProfilingEnabled ? new BrightstarProfiler("Import " + _contentFileName) : null; Logging.LogDebug("Import file path calculated as '{0}'", filePath); using (_fileStream = GetImportFileStream(filePath)) { _importTripleSink = new StoreTripleSink(StoreWorker.WriteStore, JobId, Configuration.TransactionFlushTripleCount, profiler:profiler); parser.Parse(_fileStream, this, _graphUri); } StoreWorker.WriteStore.Commit(JobId, profiler); StoreWorker.InvalidateReadStore(); Logging.LogInfo("Import job completed successfully for " + _contentFileName); if (profiler != null) { Logging.LogInfo(profiler.GetLogString()); } StoreWorker.TransactionLog.LogEndSuccessfulTransaction(this); } catch (RdfParserException parserException) { ErrorMessage = parserException.Message; ExceptionDetail = new ExceptionDetailObject(parserException); Logging.LogInfo("Parser error processing import job on file " + _contentFileName + ". " + parserException.Message); throw; } catch (Exception ex) { ErrorMessage = "Error importing file " + _contentFileName + ". " + ex.Message; StoreWorker.TransactionLog.LogEndFailedTransaction(this); Logging.LogInfo("Error processing import job on file " + _contentFileName + ". Error Message: " + ex.Message + " Stack trace: " + ex.StackTrace); throw; } }
public void Run() { try { var jobGuid = Guid.Parse(_jobId); using (_importStream = _importSource.OpenRead()) { var parser = new NTriplesParser(); _importTripleSink = new StoreTripleSink(_worker.WriteStore, jobGuid, Configuration.TransactionFlushTripleCount); parser.Parse(_importStream, this, _graphUri); _importStream.Close(); } _worker.WriteStore.Commit(jobGuid); _worker.InvalidateReadStore(); } catch (RdfParserException parserException) { Logging.LogError( BrightstarEventId.ImportDataError, "Encountered parser error : {0}", parserException); _statusCallback(_jobId, String.Format("Import failed due to parser error: {0}", parserException)); Errors = true; ErrorMessage = parserException.HaveLineNumber ? String.Format("Parser error at line {0}: {1}", parserException.LineNumber, parserException.Message) : String.Format("Parser error: {0}", parserException.Message); } catch (Exception ex) { Logging.LogError(BrightstarEventId.JobProcessingError, "Error processing import job on source " + _importSource + ". Error Message: " + ex.Message + " Stack trace: " + ex.StackTrace); throw; } }
/// <summary> /// Parse from a text reader /// </summary> /// <param name="reader">The reader providing the data to be parsed</param> /// <param name="sink">The target for the parsed RDF statements</param> /// <param name="defaultGraphUri">The default graph URI to assign to each of the parsed statements</param> public void Parse(TextReader reader, ITripleSink sink, string defaultGraphUri) { _sink = sink; _defaultGraphUri = defaultGraphUri; _rdfReader.Load(this, reader); }
public BrightstarTripleSinkAdapter(ITripleSink rdfTripleSink) { _sink = rdfTripleSink; }