@@ -14,6 +14,8 @@ use oxrdf::{
1414use scraper:: { ElementRef , Html , node:: Element } ;
1515use tracing:: trace;
1616
17+ pub mod vocabs;
18+
1719pub fn process (
1820 input : & str ,
1921 base : Iri < String > ,
@@ -35,7 +37,7 @@ fn property_copying(graph: &mut Graph) {
3537 new_triples. clear ( ) ;
3638 added_any = false ;
3739
38- for copy_triple in graph. triples_for_predicate ( rdfa_vocab :: COPY ) {
40+ for copy_triple in graph. triples_for_predicate ( vocabs :: rdfa :: COPY ) {
3941 let copy_target: oxrdf:: NamedOrBlankNodeRef = match copy_triple. object {
4042 TermRef :: NamedNode ( n) => n. into ( ) ,
4143 TermRef :: BlankNode ( n) => n. into ( ) ,
@@ -44,7 +46,11 @@ fn property_copying(graph: &mut Graph) {
4446 }
4547 } ;
4648
47- if !graph. contains ( TripleRef :: new ( copy_target, rdf:: TYPE , rdfa_vocab:: PATTERN ) ) {
49+ if !graph. contains ( TripleRef :: new (
50+ copy_target,
51+ rdf:: TYPE ,
52+ vocabs:: rdfa:: PATTERN ,
53+ ) ) {
4854 continue ; // TODO: warning?
4955 }
5056
@@ -65,20 +71,24 @@ fn property_copying(graph: &mut Graph) {
6571 // Step 2: remove
6672 {
6773 let mut triples_to_remove = Vec :: new ( ) ;
68- for copy_triple in graph. triples_for_predicate ( rdfa_vocab :: COPY ) {
74+ for copy_triple in graph. triples_for_predicate ( vocabs :: rdfa :: COPY ) {
6975 triples_to_remove. push ( copy_triple. into_owned ( ) ) ;
7076 let copy_target: oxrdf:: NamedOrBlankNodeRef = match copy_triple. object {
7177 TermRef :: NamedNode ( n) => n. into ( ) ,
7278 TermRef :: BlankNode ( n) => n. into ( ) ,
7379 TermRef :: Literal ( _) => continue ,
7480 } ;
7581
76- if !graph. contains ( TripleRef :: new ( copy_target, rdf:: TYPE , rdfa_vocab:: PATTERN ) ) {
82+ if !graph. contains ( TripleRef :: new (
83+ copy_target,
84+ rdf:: TYPE ,
85+ vocabs:: rdfa:: PATTERN ,
86+ ) ) {
7787 continue ;
7888 }
7989
8090 triples_to_remove. push (
81- TripleRef :: new ( copy_triple. subject , rdf:: TYPE , rdfa_vocab :: PATTERN ) . into_owned ( ) ,
91+ TripleRef :: new ( copy_triple. subject , rdf:: TYPE , vocabs :: rdfa :: PATTERN ) . into_owned ( ) ,
8292 ) ;
8393
8494 for trip in graph. triples_for_subject ( copy_target) {
@@ -366,7 +376,7 @@ impl<H: HostLanguage> ResolverData<H> {
366376 // > subject = base
367377 oxrdf:: NamedNodeRef :: new_unchecked ( & self . base ) ,
368378 // > predicate = http://www.w3.org/ns/rdfa#usesVocabulary
369- rdfa_vocab :: USES_VOCABULARY ,
379+ vocabs :: rdfa :: USES_VOCABULARY ,
370380 // > object = value from @vocab
371381 & vocab,
372382 ) ) ;
@@ -1466,51 +1476,6 @@ pub enum Error {
14661476 LanguageIdentifierError ( icu_locale:: ParseError ) ,
14671477}
14681478
1469- mod dc_vocab {
1470- pub static DESCRIPTION : oxrdf:: NamedNodeRef =
1471- oxrdf:: NamedNodeRef :: new_unchecked ( "http://purl.org/dc/terms/description" ) ;
1472- }
1473-
1474- mod xhv_vocab {
1475- pub static ROLE : oxrdf:: NamedNodeRef =
1476- oxrdf:: NamedNodeRef :: new_unchecked ( "http://www.w3.org/1999/xhtml/vocab#role" ) ;
1477- }
1478-
1479- mod rdfa_vocab {
1480- pub static COPY : oxrdf:: NamedNodeRef =
1481- oxrdf:: NamedNodeRef :: new_unchecked ( "http://www.w3.org/ns/rdfa#copy" ) ;
1482-
1483- pub static PATTERN : oxrdf:: NamedNodeRef =
1484- oxrdf:: NamedNodeRef :: new_unchecked ( "http://www.w3.org/ns/rdfa#Pattern" ) ;
1485-
1486- pub static ERROR : oxrdf:: NamedNodeRef =
1487- oxrdf:: NamedNodeRef :: new_unchecked ( "http://www.w3.org/ns/rdfa#Error" ) ;
1488-
1489- pub static WARNING : oxrdf:: NamedNodeRef =
1490- oxrdf:: NamedNodeRef :: new_unchecked ( "http://www.w3.org/ns/rdfa#Warning" ) ;
1491-
1492- pub static DOCUMENT_ERROR : oxrdf:: NamedNodeRef =
1493- oxrdf:: NamedNodeRef :: new_unchecked ( "http://www.w3.org/ns/rdfa#DocumentError" ) ;
1494-
1495- pub static VOCAB_REFERENCE_ERROR : oxrdf:: NamedNodeRef =
1496- oxrdf:: NamedNodeRef :: new_unchecked ( "http://www.w3.org/ns/rdfa#VocabReferenceError" ) ;
1497-
1498- pub static UNRESOLVED_CURIE : oxrdf:: NamedNodeRef =
1499- oxrdf:: NamedNodeRef :: new_unchecked ( "http://www.w3.org/ns/rdfa#UnresolvedCurie" ) ;
1500-
1501- pub static UNRESOLVED_TERM : oxrdf:: NamedNodeRef =
1502- oxrdf:: NamedNodeRef :: new_unchecked ( "http://www.w3.org/ns/rdfa#UnresolvedTerm" ) ;
1503-
1504- pub static PREFIX_REDEFINITION : oxrdf:: NamedNodeRef =
1505- oxrdf:: NamedNodeRef :: new_unchecked ( "http://www.w3.org/ns/rdfa#PrefixRedefinition" ) ;
1506-
1507- pub static CONTEXT_PROPERTY : oxrdf:: NamedNodeRef =
1508- oxrdf:: NamedNodeRef :: new_unchecked ( "http://www.w3.org/ns/rdfa#context" ) ;
1509-
1510- pub static USES_VOCABULARY : oxrdf:: NamedNodeRef =
1511- oxrdf:: NamedNodeRef :: new_unchecked ( "http://www.w3.org/ns/rdfa#usesVocabulary" ) ;
1512- }
1513-
15141479struct RDFaProcessor < ' o , ' p > {
15151480 output : RefCell < OutputGraph < ' o > > ,
15161481 processor : RefCell < ProcessorGraph < ' p > > ,
@@ -1535,7 +1500,7 @@ impl<'p> ProcessorGraph<'p> {
15351500 // add description
15361501 let desc = TripleRef :: new (
15371502 & warning_subj,
1538- dc_vocab :: DESCRIPTION ,
1503+ vocabs :: dc :: DESCRIPTION ,
15391504 oxrdf:: LiteralRef :: new_simple_literal ( msg) ,
15401505 ) ;
15411506 trace ! ( triple = %node, "emitting processor triple (type)" ) ;
@@ -1560,13 +1525,13 @@ enum PGType {
15601525impl From < PGType > for oxrdf:: NamedNodeRef < ' static > {
15611526 fn from ( val : PGType ) -> Self {
15621527 match val {
1563- PGType :: Error => rdfa_vocab :: ERROR ,
1564- PGType :: Warning => rdfa_vocab :: WARNING ,
1565- PGType :: DocumentError => rdfa_vocab :: DOCUMENT_ERROR ,
1566- PGType :: VocabReferenceError => rdfa_vocab :: VOCAB_REFERENCE_ERROR ,
1567- PGType :: UnresolvedCurie => rdfa_vocab :: UNRESOLVED_CURIE ,
1568- PGType :: UnresolvedTerm => rdfa_vocab :: UNRESOLVED_TERM ,
1569- PGType :: PrefixRedefinition => rdfa_vocab :: PREFIX_REDEFINITION ,
1528+ PGType :: Error => vocabs :: rdfa :: ERROR ,
1529+ PGType :: Warning => vocabs :: rdfa :: WARNING ,
1530+ PGType :: DocumentError => vocabs :: rdfa :: DOCUMENT_ERROR ,
1531+ PGType :: VocabReferenceError => vocabs :: rdfa :: VOCAB_REFERENCE_ERROR ,
1532+ PGType :: UnresolvedCurie => vocabs :: rdfa :: UNRESOLVED_CURIE ,
1533+ PGType :: UnresolvedTerm => vocabs :: rdfa :: UNRESOLVED_TERM ,
1534+ PGType :: PrefixRedefinition => vocabs :: rdfa :: PREFIX_REDEFINITION ,
15701535 }
15711536 }
15721537}
@@ -1587,14 +1552,8 @@ pub fn initial_context_terms() -> &'static BTreeMap<String, oxrdf::NamedNode> {
15871552 "describedBy" . to_string ( ) ,
15881553 oxrdf:: NamedNode :: new_unchecked ( "http://www.w3.org/2007/05/powder-s#describedby" ) ,
15891554 ) ,
1590- (
1591- "license" . to_string ( ) ,
1592- oxrdf:: NamedNode :: new_unchecked ( "http://www.w3.org/1999/xhtml/vocab#license" ) ,
1593- ) ,
1594- (
1595- "role" . to_string ( ) ,
1596- oxrdf:: NamedNode :: new_unchecked ( "http://www.w3.org/1999/xhtml/vocab#role" ) ,
1597- ) ,
1555+ ( "license" . to_string ( ) , vocabs:: xhv:: LICENSE . into ( ) ) ,
1556+ ( "role" . to_string ( ) , vocabs:: xhv:: ROLE . into ( ) ) ,
15981557 ]
15991558 . into_iter ( )
16001559 . collect ( )
@@ -1833,7 +1792,7 @@ impl<'o, 'p> RDFaProcessor<'o, 'p> {
18331792 // > defined at http://www.w3.org/1999/xhtml/vocab.
18341793 self . output
18351794 . get_mut ( )
1836- . emit ( TripleRef :: new ( & role_subject, xhv_vocab :: ROLE , & role) ) ;
1795+ . emit ( TripleRef :: new ( & role_subject, vocabs :: xhv :: ROLE , & role) ) ;
18371796 }
18381797 }
18391798
0 commit comments