rdfref-query.sty 2.93 KB
Newer Older
Andreas Zwinkau's avatar
initial  
Andreas Zwinkau committed
1
\ProvidesPackage{rdfref-query}
Andreas Zwinkau's avatar
Revised  
Andreas Zwinkau committed
2
\RequirePackage{rdfref-core}
Andreas Zwinkau's avatar
initial  
Andreas Zwinkau committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
\def\Var#1{Variable: #1}
\def\Value#1{Value: #1}

\newcommand\BindVal[2]{%
\IfBeginWith{#2}{?}{%
\ifcsdef{rdfquery@#2}{\def#1{\Value{\csuse{rdfquery@#2}}}}{\def#1{\Var{#2}}}%
}{\def#1{\Value{#2}}}%
}

\newcommand\SaveVal[2]{%
\csedef{rdfquery@#1}{#2}%
}

\newcommand\GetValProperty[2]{%
 \expandafter\GetProperty\expandafter{\GetVal{#1}}{#2}%
}


\newcommand\GetVal[1]{%
\csuse{rdfquery@#1}%
}


\newcommand\QueryType[3]{%
\bgroup%
\def\Var##1{v}%
\def\Value##1{l}%
\xdef\qtype{#1#2#3}%
\egroup%
}
\newcommand\DeclareQueryProcessor[2]{%
\long\csgdef{rdfquery@proc@#1}##1{%
\long\def\continue{##1}%
#2}%
}

\DeclareQueryProcessor{vlv}{%
% why we redefine \Value and \Var? I should write comments next time
\def\Value##1{##1}%
\def\Var##1{##1}%
\MapPropertyList\predicate{%
\SaveVal\subject{\ifx\\##1\\\else\First##1\fi}%
\SaveVal\object{\ifx\\##1\\\else\Second##1\fi}%
\continue
}%
}

\DeclareQueryProcessor{vll}{%
	% this is first querry processor after two years, I have no idea what 
	% needs to be done
\def\Value##1{##1}
\def\Var##1{##1}
\MapPropertyList\predicate{%
	% only do action if searched \object is equal to current objeect
	\IfStrEq{\object}{\ifx\\##1\\\else\Second##1\fi}{%
	% ##1 is variable passed by \do, two tokens are here:
	  \SaveVal\subject{\ifx\\##1\\\else\First##1\fi}%
	  \SaveVal\object{\ifx\\##1\\\else\Second##1\fi}%
    \continue}{}%
 }%
}

Andreas Zwinkau's avatar
Andreas Zwinkau committed
65

Andreas Zwinkau's avatar
initial  
Andreas Zwinkau committed
66
\DeclareQueryProcessor{llv}{%
Andreas Zwinkau's avatar
Andreas Zwinkau committed
67 68 69 70 71 72 73 74
  \def\Value##1{##1}%
  \def\Var##1{##1}%
  % Subject can have multiple values of property, so we need to loop over them
  \MapPropertyList\predicate{%
    \IfStrEq\subject{\ifx\\##1\\\else\First##1\fi}{%
      \SaveVal\object{\ifx\\##1\\\else\Second##1\fi}%
    \continue}{}%
  }%
Andreas Zwinkau's avatar
initial  
Andreas Zwinkau committed
75 76
}%

Andreas Zwinkau's avatar
Andreas Zwinkau committed
77

Andreas Zwinkau's avatar
initial  
Andreas Zwinkau committed
78 79 80 81
\DeclareQueryProcessor{lvv}{%
 \def\Value##1{##1}%
 \def\Var##1{##1}%
 \MapSubjectList\subject{%
Andreas Zwinkau's avatar
Andreas Zwinkau committed
82 83
  \SaveVal\predicate{\ifx\\##1\\\else\First##1\fi}%
  \SaveVal\object{\ifx\\##1\\\else\Second##1\fi}%
Andreas Zwinkau's avatar
initial  
Andreas Zwinkau committed
84 85 86 87 88 89 90 91
  \continue%
 }%
}

\DeclareQueryProcessor{lvl}{%
 \def\Value##1{##1}%
 \def\Var##1{##1}%
 \MapSubjectList\subject{%
Andreas Zwinkau's avatar
Andreas Zwinkau committed
92 93 94
   % \IfStrEq{\GetProperty{\subject}{##1}}{\object}{%
   \IfStrEq{\ifx\\##1\\\else\Second##1\fi}{\object}{%
    \SaveVal\predicate{\ifx\\##1\\\else\First##1\fi}% 
Andreas Zwinkau's avatar
initial  
Andreas Zwinkau committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
    \continue%
   }{}%
 }% 
}

\DeclareQueryProcessor{lll}{%
\def\Value##1{##1}%
\def\Var##1{##1}%
\IfStrEq{\GetProperty{\subject}{\predicate}}{\object}{\continue}{Neshoduj\'i se}
}



\newcommand\Bind[4]{%
\bgroup%
\BindVal\subject{#1}%
\BindVal\predicate{#2}%
\BindVal\object{#3}%
\QueryType\subject\predicate\object%
\ifcsdef{rdfquery@proc@\qtype}{\csuse{rdfquery@proc@\qtype}{#4}}{\typeout{\detokenize{Neznám procesor} \qtype}}%
\egroup%
}

% what is the purpose of this command?
\newcommand\OptionalBind[3]{%
%\bgroup%
\BindVal\subject{#1}%
\BindVal\predicate{#2}%
\BindVal\object{#3}%
\QueryType\subject\predicate\object%
\ifcsdef{rdfquery@proc@\qtype}{\csuse{rdfquery@proc@\qtype}{}}{\typeout{\detokenize{Neznám procesor} \qtype}}%
%#4
%\egroup%  
}

\endinput