Skip to content

Commit 65783cb

Browse files
committed
update to latest oxrdf libs, remove rd-canon
1 parent 903bfbc commit 65783cb

18 files changed

+122
-150
lines changed

Cargo.lock

Lines changed: 13 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ rust-version = "1.82.0"
1414

1515
[workspace.dependencies]
1616
html2rdf = { path = "html2rdf" }
17-
oxiri = "^0.2.11"
18-
oxrdf = "^0.2.4"
19-
oxttl = "^0.1.8"
17+
oxiri = "0.2.11"
18+
oxrdf = "0.3.3"
19+
oxttl = "0.2.3"

html2rdf/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ itertools = "0.14.0"
1818
oxiri = { workspace = true }
1919
oxrdf = { workspace = true }
2020
oxsdatatypes = "0.2.2"
21-
rdf-canon = "0.15.1"
2221
rxml_validation = "0.11.0"
2322
scraper = "0.23.1"
2423
vec1 = "1.12.1"
2524

2625
[dev-dependencies]
2726
insta = { version = "1.43.1", features = ["glob"] }
27+
oxrdf = { workspace = true, features = ["rdfc-10"] }
2828
oxttl = { workspace = true }
2929
pretty_assertions = "1.4.1"
3030
rstest = { version = "0.25.0", default-features = false, features = ["crate-name"] }

html2rdf/src/lib.rs

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::cell::RefCell;
22
use std::collections::BTreeMap;
3-
use std::ops::Not;
43
use std::rc::Rc;
54
use std::{borrow::Cow, str::FromStr};
65

@@ -114,15 +113,15 @@ pub fn parse(
114113
let base_sel = scraper::selector::Selector::parse("html>head>base").unwrap();
115114

116115
if let Some(base_el) = doc.select(&base_sel).next()
117-
&& let Some(base_href) = base_el.attr("href") {
118-
base =
119-
Iri::parse(base_href.to_string()).map_err(|source| Error::IriParseError {
120-
source,
121-
iri: base_href.to_string(),
122-
})?;
123-
124-
trace!("<base> found: {base}");
125-
}
116+
&& let Some(base_href) = base_el.attr("href")
117+
{
118+
base = Iri::parse(base_href.to_string()).map_err(|source| Error::IriParseError {
119+
source,
120+
iri: base_href.to_string(),
121+
})?;
122+
123+
trace!("<base> found: {base}");
124+
}
126125

127126
let eval_context = EvaluationContext::new(base);
128127
proc.run(eval_context, doc)?;
@@ -815,7 +814,7 @@ impl HostLanguage for &HTMLHost {
815814
}
816815

817816
fn emit_processor(pg: &mut Graph, pg_type: PGType, msg: &str) {
818-
let warning_subj: oxrdf::Subject = oxrdf::BlankNode::default().into();
817+
let warning_subj: oxrdf::NamedOrBlankNode = oxrdf::BlankNode::default().into();
819818
let pg_type: oxrdf::NamedNodeRef = pg_type.into();
820819
// new bnode is-a PGClass
821820
let node = TripleRef::new(&warning_subj, oxrdf::vocab::rdf::TYPE, pg_type);
@@ -970,9 +969,11 @@ impl<'o, 'p> RDFaProcessor<'o, 'p> {
970969
trace!(
971970
"{}{}{} {attrs}",
972971
ancestor_stack.join(">"),
973-
if ancestor_stack
974-
.is_empty()
975-
.not() { ">" } else { Default::default() },
972+
if ancestor_stack.is_empty() {
973+
Default::default()
974+
} else {
975+
">"
976+
},
976977
el.name()
977978
);
978979
}
@@ -1458,11 +1459,12 @@ impl<'o, 'p> RDFaProcessor<'o, 'p> {
14581459
// “If in any of the previous steps a new subject
14591460
// was set to a non-null value different from the parent object;
14601461
if let Some(ns) = &local.new_subject
1461-
&& Some(ns) != eval_context.parent_object.as_ref() {
1462-
// “The list mapping taken from the evaluation context is set to a new, empty mapping.
1463-
trace!("- Setting new list mapping");
1464-
local.list_mappings = Default::default();
1465-
}
1462+
&& Some(ns) != eval_context.parent_object.as_ref()
1463+
{
1464+
// “The list mapping taken from the evaluation context is set to a new, empty mapping.
1465+
trace!("- Setting new list mapping");
1466+
local.list_mappings = Default::default();
1467+
}
14661468

14671469
// 9.
14681470
// “If in any of the previous steps a current object resource was set to a non-null value,
@@ -1742,49 +1744,50 @@ impl<'o, 'p> RDFaProcessor<'o, 'p> {
17421744
// “If the skip element flag is 'false', and new subject was set to a non-null value,
17431745
// then any incomplete triples within the current context should be completed:
17441746
if !local.skip_element
1745-
&& let Some(new_subject) = &local.new_subject {
1746-
// “The list of incomplete triples from the current evaluation context
1747-
// (not the local list of incomplete triples) will contain zero or more predicate
1748-
// IRIs. This list is iterated over and each of the predicates is used with parent
1749-
// subject and new subject to generate a triple or add a new element to the local
1750-
// list mapping. Note that at each level there are two lists of incomplete triples;
1751-
// one for the current processing level (which is passed to each child element in
1752-
// the previous step), and one that was received as part of the evaluation context.
1753-
// It is the latter that is used in processing during this step.
1754-
for incomplete in eval_context.incomplete_triples.iter() {
1755-
// “Note that each incomplete triple has a direction value that is used to determine
1756-
// what will become the subject, and what will become the object, of each generated triple:
1757-
match incomplete {
1758-
// “If direction is 'none',
1759-
// the new subject is added to the list from the iterated incomplete triple.
1760-
IncompleteTriple::List(list) => list
1761-
.borrow_mut()
1762-
.push(Rc::new(new_subject.as_ref().clone().into())),
1763-
// “If direction is 'forward' then the following triple is generated:
1764-
IncompleteTriple::Forward(predicate) => {
1765-
self.emit_output(TripleRef::new(
1766-
// subject = parent subject
1767-
eval_context.parent_subject.as_ref(),
1768-
// predicate = the predicate from the iterated incomplete triple
1769-
predicate.as_ref(),
1770-
// object = new subject
1771-
new_subject.as_ref(),
1772-
));
1773-
}
1774-
// “If direction is 'reverse' then this is the triple generated:
1775-
IncompleteTriple::Reverse(predicate) => {
1776-
self.emit_output(TripleRef::new(
1777-
// subject = new subject
1778-
new_subject.as_ref(),
1779-
// predicate = the predicate from the iterated incomplete triple
1780-
predicate.as_ref(),
1781-
// object = parent subject
1782-
eval_context.parent_subject.as_ref(),
1783-
));
1784-
}
1747+
&& let Some(new_subject) = &local.new_subject
1748+
{
1749+
// “The list of incomplete triples from the current evaluation context
1750+
// (not the local list of incomplete triples) will contain zero or more predicate
1751+
// IRIs. This list is iterated over and each of the predicates is used with parent
1752+
// subject and new subject to generate a triple or add a new element to the local
1753+
// list mapping. Note that at each level there are two lists of incomplete triples;
1754+
// one for the current processing level (which is passed to each child element in
1755+
// the previous step), and one that was received as part of the evaluation context.
1756+
// It is the latter that is used in processing during this step.
1757+
for incomplete in eval_context.incomplete_triples.iter() {
1758+
// “Note that each incomplete triple has a direction value that is used to determine
1759+
// what will become the subject, and what will become the object, of each generated triple:
1760+
match incomplete {
1761+
// “If direction is 'none',
1762+
// the new subject is added to the list from the iterated incomplete triple.
1763+
IncompleteTriple::List(list) => list
1764+
.borrow_mut()
1765+
.push(Rc::new(new_subject.as_ref().clone().into())),
1766+
// “If direction is 'forward' then the following triple is generated:
1767+
IncompleteTriple::Forward(predicate) => {
1768+
self.emit_output(TripleRef::new(
1769+
// subject = parent subject
1770+
eval_context.parent_subject.as_ref(),
1771+
// predicate = the predicate from the iterated incomplete triple
1772+
predicate.as_ref(),
1773+
// object = new subject
1774+
new_subject.as_ref(),
1775+
));
1776+
}
1777+
// “If direction is 'reverse' then this is the triple generated:
1778+
IncompleteTriple::Reverse(predicate) => {
1779+
self.emit_output(TripleRef::new(
1780+
// subject = new subject
1781+
new_subject.as_ref(),
1782+
// predicate = the predicate from the iterated incomplete triple
1783+
predicate.as_ref(),
1784+
// object = parent subject
1785+
eval_context.parent_subject.as_ref(),
1786+
));
17851787
}
17861788
}
17871789
}
1790+
}
17881791

17891792
// 13.
17901793
// “Next, all elements that are children of the current element are processed

html2rdf/src/reference_impl.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ struct EvaluationContext {
188188

189189
// “The parent subject. The initial value will be the same as the initial value of base,
190190
// but it will usually change during the course of processing.
191-
parent_subject: Rc<oxrdf::Subject>,
191+
parent_subject: Rc<oxrdf::NamedOrBlankNode>,
192192

193193
// “The parent object. In some situations the object of a statement becomes the subject
194194
// of any nested statements, and this member is used to convey this value. Note that this
195195
// value may be a bnode, since in some situations a number of nested statements are grouped
196196
// together on one bnode. This means that the bnode must be set in the containing statement and passed down.
197-
parent_object: Option<Rc<oxrdf::Subject>>, // note that this is a subject, not an object, but the parent object cannot be a term
197+
parent_object: Option<Rc<oxrdf::NamedOrBlankNode>>, // note that this is a subject, not an object, but the parent object cannot be a term
198198

199199
// “A list of current, in-scope IRI mappings.
200200
iri_mappings: Rc<curie::PrefixMapping>,
@@ -237,11 +237,11 @@ struct LocalScope<'a> {
237237
skip_element: bool,
238238
// “A new subject value, which once calculated will set the parent subject in an evaluation context,
239239
// as well as being used to complete any incomplete triples, as described in the next section.
240-
new_subject: Option<Rc<oxrdf::Subject>>,
240+
new_subject: Option<Rc<oxrdf::NamedOrBlankNode>>,
241241
// “A value for the current object resource, the resource to use when creating triples that have a resource object.
242-
current_object_resource: Option<Rc<oxrdf::Subject>>,
242+
current_object_resource: Option<Rc<oxrdf::NamedOrBlankNode>>,
243243
// “A value for the typed resource, the source for creating rdf:type relationships to types specified in @typeof.
244-
typed_resource: Option<Rc<oxrdf::Subject>>,
244+
typed_resource: Option<Rc<oxrdf::NamedOrBlankNode>>,
245245
// “The local term mappings, a list of terms and their associated IRIs.
246246
term_mappings: Rc<BTreeMap<String, oxrdf::NamedNode>>,
247247
// “The local list mapping, mapping IRIs to lists
@@ -704,7 +704,7 @@ impl HostLanguage for &HTMLHost {
704704
}
705705

706706
fn emit_processor(pg: &mut Graph, pg_type: PGType, msg: &str) {
707-
let warning_subj: oxrdf::Subject = oxrdf::BlankNode::default().into();
707+
let warning_subj: oxrdf::NamedOrBlankNode = oxrdf::BlankNode::default().into();
708708
let pg_type: oxrdf::NamedNodeRef = pg_type.into();
709709
// new bnode is-a PGClass
710710
let node = TripleRef::new(&warning_subj, oxrdf::vocab::rdf::TYPE, pg_type);
@@ -743,7 +743,7 @@ impl<'o, 'p> RDFaProcessor<'o, 'p> {
743743
fn run(&mut self, eval_context: EvaluationContext, html: Html) -> Result<(), Error> {
744744
enum S<'a> {
745745
Child(ElementRef<'a>, Rc<EvaluationContext>),
746-
OutputList(Rc<oxrdf::Subject>, Rc<RefCell<ListMapping>>),
746+
OutputList(Rc<oxrdf::NamedOrBlankNode>, Rc<RefCell<ListMapping>>),
747747
}
748748

749749
// TODO: we need a marker on the stack to emit list elements
@@ -1066,8 +1066,8 @@ impl<'o, 'p> RDFaProcessor<'o, 'p> {
10661066
let inlist = el.attr("inlist").is_some();
10671067

10681068
let has_about = el.attr("about").is_some();
1069-
let about: Option<Rc<oxrdf::Subject>> =
1070-
handle_safecurie_or_curie_or_iri(el.attr("about")).map(|x| Rc::new(x.into()));
1069+
let about: Option<Rc<oxrdf::NamedOrBlankNode>> =
1070+
handle_safecurie_or_curie_or_iri(el.attr("about")).map(Rc::new);
10711071

10721072
let type_of = handle_term_or_curie_or_absiri_s(el.attr("typeof"));
10731073

@@ -1076,12 +1076,12 @@ impl<'o, 'p> RDFaProcessor<'o, 'p> {
10761076
let src = handle_iri(el.attr("src"));
10771077

10781078
// read from the "resource attributes"
1079-
let resource_iri: Option<Rc<oxrdf::Subject>> = resource
1079+
let resource_iri: Option<Rc<oxrdf::NamedOrBlankNode>> = resource
10801080
.or_else(|| href.map(NamedOrBlankNode::from))
10811081
.or_else(|| src.map(NamedOrBlankNode::from))
1082-
.map(|x| Rc::new(oxrdf::Subject::from(x)));
1082+
.map(Rc::new);
10831083

1084-
let _new_subject: Rc<oxrdf::Subject>;
1084+
let _new_subject: Rc<oxrdf::NamedOrBlankNode>;
10851085

10861086
//5.
10871087
// “If the current element contains no @rel or @rev attribute,

0 commit comments

Comments
 (0)