|
1 | 1 | use std::cell::RefCell; |
2 | 2 | use std::collections::BTreeMap; |
3 | | -use std::ops::Not; |
4 | 3 | use std::rc::Rc; |
5 | 4 | use std::{borrow::Cow, str::FromStr}; |
6 | 5 |
|
@@ -114,15 +113,15 @@ pub fn parse( |
114 | 113 | let base_sel = scraper::selector::Selector::parse("html>head>base").unwrap(); |
115 | 114 |
|
116 | 115 | 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 | + } |
126 | 125 |
|
127 | 126 | let eval_context = EvaluationContext::new(base); |
128 | 127 | proc.run(eval_context, doc)?; |
@@ -815,7 +814,7 @@ impl HostLanguage for &HTMLHost { |
815 | 814 | } |
816 | 815 |
|
817 | 816 | 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(); |
819 | 818 | let pg_type: oxrdf::NamedNodeRef = pg_type.into(); |
820 | 819 | // new bnode is-a PGClass |
821 | 820 | let node = TripleRef::new(&warning_subj, oxrdf::vocab::rdf::TYPE, pg_type); |
@@ -970,9 +969,11 @@ impl<'o, 'p> RDFaProcessor<'o, 'p> { |
970 | 969 | trace!( |
971 | 970 | "{}{}{} {attrs}", |
972 | 971 | 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 | + }, |
976 | 977 | el.name() |
977 | 978 | ); |
978 | 979 | } |
@@ -1458,11 +1459,12 @@ impl<'o, 'p> RDFaProcessor<'o, 'p> { |
1458 | 1459 | // “If in any of the previous steps a new subject |
1459 | 1460 | // was set to a non-null value different from the parent object; |
1460 | 1461 | 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 | + } |
1466 | 1468 |
|
1467 | 1469 | // 9. |
1468 | 1470 | // “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> { |
1742 | 1744 | // “If the skip element flag is 'false', and new subject was set to a non-null value, |
1743 | 1745 | // then any incomplete triples within the current context should be completed: |
1744 | 1746 | 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 | + )); |
1785 | 1787 | } |
1786 | 1788 | } |
1787 | 1789 | } |
| 1790 | + } |
1788 | 1791 |
|
1789 | 1792 | // 13. |
1790 | 1793 | // “Next, all elements that are children of the current element are processed |
|
0 commit comments