rdfref-core.sty 2.54 KB
Newer Older
Andreas Zwinkau's avatar
initial  
Andreas Zwinkau committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
\ProvidesPackage{rdfref-core}
\RequirePackage{etoolbox,xstring}
\def\Nil{}%
\def\First#1#2{#1}
\def\Second#1#2{#2}

\def\parsecolon#1:#2\relax{\ifx#2\Nil\Nil\else#1\fi}%
\newcommand\RdfPrefix[1]{%
\parsecolon#1:\Nil\relax%
}
\newcommand\AddTriple[3]{%
%\edef\rdf@object{#3}
\immediate\write\@auxout{\noexpand\LoadTriple{#1}{#2}{\expandafter\detokenize\expandafter{#3}}}%
%\immediate\write\@auxout{\noexpand\LoadTriple{#1}{#2}{\rdf@object}}
}

% If we need to write something expanded, like \thepage
\newcommand\AddTripleEx[3]{%
% \edef\rdf@object{#3}%
% \immediate\write\@auxout{\noexpand\LoadTriple{#1}{#2}{\rdf@object}}%
\protected@write\@auxout{}{\protect\LoadTriple{#1}{#2}{#3}}
}

\newcommand\SetProperty[3]{%
Andreas Zwinkau's avatar
Andreas Zwinkau committed
25 26
% \protected@csxdef{rdf@#1@#2}{#3}%
  \listcsxadd{rdf@#1@#2}{#3}%
Andreas Zwinkau's avatar
initial  
Andreas Zwinkau committed
27 28 29 30 31
}

\newcommand\IfProperty[2]{%
\ifcsdef{rdf@#1@#2}%
}
Andreas Zwinkau's avatar
Andreas Zwinkau committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

% we use etoolbox's list to store property array
% character | is used to delimit the records, it has
% changed catcode, so we must do some trickery to parse 
% it correctly
\@tempcnta=\the\catcode`\|
\catcode`\|=3
\def\MatchFirstProperty#1|#2\@nil{#1}

\newcommand\GetFirstProperty[1]{%
  \MatchFirstProperty#1|\@nil
}
\catcode`\|=\the\@tempcnta

% Object can have multiple occassions of an property, 
% we get only the first one with \GetProperty command
% You need to use looping commands to get also the other 
% values
Andreas Zwinkau's avatar
initial  
Andreas Zwinkau committed
50
\newcommand\GetProperty[2]{%
Andreas Zwinkau's avatar
Andreas Zwinkau committed
51 52 53 54 55 56
  \IfProperty{#1}{#2}{%
    \edef\@temp{\csname rdf@#1@#2\endcsname}%
    \expandafter\GetFirstProperty\expandafter{\@temp}%
    }{%
    \PropertyNotDef{#1}{#2}%
  }%
Andreas Zwinkau's avatar
initial  
Andreas Zwinkau committed
57 58 59
}
\newcommand\PropertyNotDef[2]{%
???%
Andreas Zwinkau's avatar
Andreas Zwinkau committed
60
\typeout{rdf warning: subject #1 has no property #2}%
Andreas Zwinkau's avatar
initial  
Andreas Zwinkau committed
61
}
Andreas Zwinkau's avatar
Andreas Zwinkau committed
62 63 64 65 66 67 68 69 70

% #1 object, #2 property
\newcommand\MapObjectList[3]{%
  \def\do##1{#3}%
  \ifcsdef{rdf@#1@#2}{%
    \dolistcsloop{rdf@#1@#2}%
  }{}%
}

Andreas Zwinkau's avatar
initial  
Andreas Zwinkau committed
71 72 73 74 75 76 77 78 79 80 81 82
\edef\Hash{\string#}

\newcommand\Prefix[2]{%
%\edef\fuf{Prefix #2}
\ifcsdef{rdfprefix@#1}{%
\IfStrEq{\csuse{rdfprefix@#1}}{#2}{%
\typeout{Prefix #1 already exists for #2}%
}{\typeout{Prefix clash, uri #2 has already prefix \csuse{rdfprefix@#1}, #1 provided}%
}}{%
\csgdef{rdfprefix@#1}{#2}%
}
}
Andreas Zwinkau's avatar
Andreas Zwinkau committed
83 84
\newcommand\SubjectListAdd[3]{%
  \listcsgadd{sbjlst@#1}{{#2}{#3}}%
Andreas Zwinkau's avatar
initial  
Andreas Zwinkau committed
85 86
}
\newcommand\MapSubjectList[2]{%
Andreas Zwinkau's avatar
Andreas Zwinkau committed
87 88 89 90 91
  % \def\tmp@sbj{\MapObjectList{
  \def\do##1{#2}%
  \ifcsdef{sbjlst@#1}{%
    \dolistcsloop{sbjlst@#1}%
  }{}%
Andreas Zwinkau's avatar
initial  
Andreas Zwinkau committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
}

\newcommand\PropertyListAdd[3]{%
\listcsgadd{prprtlst@#2}{{#1}{#3}}%
}
\newcommand\MapPropertyList[2]{%
\def\do##1{#2}%
\ifcsdef{prprtlst@#1}{%
\dolistcsloop{prprtlst@#1}%
}{}%
}


\newcommand\LoadTriple[3]{%
\SetProperty{#1}{#2}{#3}%
Andreas Zwinkau's avatar
Andreas Zwinkau committed
107
\SubjectListAdd{#1}{#2}{#3}%
Andreas Zwinkau's avatar
initial  
Andreas Zwinkau committed
108 109 110 111
\PropertyListAdd{#1}{#2}{#3}%
}