|
|
@ -270,6 +270,33 @@ impl<R: Read> FromReadTurtleReader<R> { |
|
|
|
pub fn prefixes(&self) -> &HashMap<String, Iri<String>> { |
|
|
|
pub fn prefixes(&self) -> &HashMap<String, Iri<String>> { |
|
|
|
&self.inner.parser.context.prefixes |
|
|
|
&self.inner.parser.context.prefixes |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// The base IRI considered at the current step of the parsing.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
/// use oxttl::TurtleParser;
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// let file = b"@base <http://example.com/> .
|
|
|
|
|
|
|
|
/// @prefix schema: <http://schema.org/> .
|
|
|
|
|
|
|
|
/// <foo> a schema:Person ;
|
|
|
|
|
|
|
|
/// schema:name \"Foo\" .";
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// let mut reader = TurtleParser::new().parse_read(file.as_ref());
|
|
|
|
|
|
|
|
/// assert!(reader.base_iri().is_none()); // No base at the beginning because none has been given to the parser.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// reader.next().unwrap()?; // We read the first triple
|
|
|
|
|
|
|
|
/// assert_eq!(reader.base_iri(), Some("http://example.com/")); // There is now a base IRI.
|
|
|
|
|
|
|
|
/// # Result::<_,Box<dyn std::error::Error>>::Ok(())
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
pub fn base_iri(&self) -> Option<&str> { |
|
|
|
|
|
|
|
self.inner |
|
|
|
|
|
|
|
.parser |
|
|
|
|
|
|
|
.context |
|
|
|
|
|
|
|
.lexer_options |
|
|
|
|
|
|
|
.base_iri |
|
|
|
|
|
|
|
.as_ref() |
|
|
|
|
|
|
|
.map(Iri::as_str) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<R: Read> Iterator for FromReadTurtleReader<R> { |
|
|
|
impl<R: Read> Iterator for FromReadTurtleReader<R> { |
|
|
@ -349,6 +376,36 @@ impl<R: AsyncRead + Unpin> FromTokioAsyncReadTurtleReader<R> { |
|
|
|
pub fn prefixes(&self) -> &HashMap<String, Iri<String>> { |
|
|
|
pub fn prefixes(&self) -> &HashMap<String, Iri<String>> { |
|
|
|
&self.inner.parser.context.prefixes |
|
|
|
&self.inner.parser.context.prefixes |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// The base IRI considered at the current step of the parsing.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
/// use oxttl::TurtleParser;
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// # #[tokio::main(flavor = "current_thread")]
|
|
|
|
|
|
|
|
/// # async fn main() -> Result<(), oxttl::ParseError> {
|
|
|
|
|
|
|
|
/// let file = b"@base <http://example.com/> .
|
|
|
|
|
|
|
|
/// @prefix schema: <http://schema.org/> .
|
|
|
|
|
|
|
|
/// <foo> a schema:Person ;
|
|
|
|
|
|
|
|
/// schema:name \"Foo\" .";
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// let mut reader = TurtleParser::new().parse_tokio_async_read(file.as_ref());
|
|
|
|
|
|
|
|
/// assert!(reader.base_iri().is_none()); // No base IRI at the beginning
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// reader.next().await.unwrap()?; // We read the first triple
|
|
|
|
|
|
|
|
/// assert_eq!(reader.base_iri(), Some("http://example.com/")); // There is now a base IRI
|
|
|
|
|
|
|
|
/// # Ok(())
|
|
|
|
|
|
|
|
/// # }
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
pub fn base_iri(&self) -> Option<&str> { |
|
|
|
|
|
|
|
self.inner |
|
|
|
|
|
|
|
.parser |
|
|
|
|
|
|
|
.context |
|
|
|
|
|
|
|
.lexer_options |
|
|
|
|
|
|
|
.base_iri |
|
|
|
|
|
|
|
.as_ref() |
|
|
|
|
|
|
|
.map(Iri::as_str) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Parses a Turtle file by using a low-level API. Can be built using [`TurtleParser::parse`].
|
|
|
|
/// Parses a Turtle file by using a low-level API. Can be built using [`TurtleParser::parse`].
|
|
|
@ -442,6 +499,33 @@ impl LowLevelTurtleReader { |
|
|
|
pub fn prefixes(&self) -> &HashMap<String, Iri<String>> { |
|
|
|
pub fn prefixes(&self) -> &HashMap<String, Iri<String>> { |
|
|
|
&self.parser.context.prefixes |
|
|
|
&self.parser.context.prefixes |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// The base IRI considered at the current step of the parsing.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
/// use oxttl::TurtleParser;
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// let file = b"@base <http://example.com/> .
|
|
|
|
|
|
|
|
/// @prefix schema: <http://schema.org/> .
|
|
|
|
|
|
|
|
/// <foo> a schema:Person ;
|
|
|
|
|
|
|
|
/// schema:name \"Foo\" .";
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// let mut reader = TurtleParser::new().parse();
|
|
|
|
|
|
|
|
/// reader.extend_from_slice(file);
|
|
|
|
|
|
|
|
/// assert!(reader.base_iri().is_none()); // No base IRI at the beginning
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// reader.read_next().unwrap()?; // We read the first triple
|
|
|
|
|
|
|
|
/// assert_eq!(reader.base_iri(), Some("http://example.com/")); // There is now a base IRI
|
|
|
|
|
|
|
|
/// # Result::<_,Box<dyn std::error::Error>>::Ok(())
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
pub fn base_iri(&self) -> Option<&str> { |
|
|
|
|
|
|
|
self.parser |
|
|
|
|
|
|
|
.context |
|
|
|
|
|
|
|
.lexer_options |
|
|
|
|
|
|
|
.base_iri |
|
|
|
|
|
|
|
.as_ref() |
|
|
|
|
|
|
|
.map(Iri::as_str) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// A [Turtle](https://www.w3.org/TR/turtle/) serializer.
|
|
|
|
/// A [Turtle](https://www.w3.org/TR/turtle/) serializer.
|
|
|
|