text:
%%%%%%%%%% various utility predicates for lists and sequences %%%%%%%%%%

flatten(T, [T]) :- (var(T); atomic(T)), !.
flatten((T1, T2), L) :- flatten(T1, L1), flatten(T2, L2), append(L1, L2, L), !.
flatten(T, [T]) :- compound(T), !.

to_sequence([T], T) :- !.
to_sequence([H|T], (H, TS)) :- to_sequence(T, TS).

member_seq(X, (Y,_)) :- X==Y, !.
member_seq(X, Y) :- X==Y, !.
member_seq(X,(_,T)) :- member_seq(X,T).

%member(X, [X|_]) :- !.
%member(X,[_|T]) :- member(X,T).

%% removes duplicates
remove_unifiable([],[]).
remove_unifiable([H|T],[H|Out]) :-
    not(member(H,T)), !, %%% check here
    remove_unifiable(T,Out).
remove_unifiable([H|T],Out) :-
    remove_unifiable(T,Out).

%% checks whether the exact syntactic form of Item appears in List
%% member_list(Item, List)
member_list(X, [Y|_]) :- X==Y, !.
member_list(X,[_|T]) :- member_list(X,T).

%% removes the exact multiple syntactic occurrences from a list
remove_duplicates([],[]).
remove_duplicates([H|T],[H|Out]) :-
    not(member_list(H,T)), !, %%% check here
    remove_duplicates(T,Out).
remove_duplicates([H|T],Out) :-
    remove_duplicates(T,Out).

%% checks whether a variation (=@=) of Item appears in List
%% member_list(Item, List)
memberEq(X,[Y|_]) :- X =@= Y, !.
memberEq(X,[_|T]) :- memberEq(X,T).

%% removes occurrences of items for which there is an
%% "equivalent" (=@=) item in a list
remove_equivalent([],[]).
remove_equivalent([H|T],[H|Out]) :-
    not(memberEq(H,T)), !,  %%% check here
    remove_equivalent(T,Out).
remove_equivalent([H|T],Out) :-
%    memberEq(H,T),
    remove_equivalent(T,Out).

:- redefine_system_predicate(print(_)).
print([H | T]) :- write_term(H, []), nl, print(T).
print([]) :- nl.

%%%%%%%%%% Predicates that implement the semantics of Description Logics %%%%%%%%%%
%%%%%%%%%% used in optimizing the expansions %%%%%%%%%%

%% using assert
%
%:- dynamic table_subsumptions/2.
%
%rdfs_subsumes(A,B) :- table_subsumptions(A,B), !.
%rdfs_subsumes(A,B) :-
%  t_rdfs_subsumes(A, B, [A]),
%  asserta(table_subsumptions(A,B)).
%
%rdfs_subsumes_0(A,B) :- table_subsumptions(A,B), !.
%rdfs_subsumes_0(A,B) :-
%  clause(A, B), not(B = (_,_)), not(edb(B)).
%  asserta(table_subsumptions(A,B)).

rdfs_subsumes(A, B) :-
	t_rdfs_subsumes(A, B, [A]).

rdfs_subsumes_0(A,B) :-
	clause(A, B), not(B = (_,_)), not(edb(B)).

t_rdfs_subsumes(A, B, L) :-
	rdfs_subsumes_0(A,B), not(member(B, L)).

t_rdfs_subsumes(A, B, IntermediateNodes) :-
	rdfs_subsumes_0(A,C), not(member(C, IntermediateNodes)),
	t_rdfs_subsumes(C, B, [C | IntermediateNodes]).

subsumptions(A,B) :- idb(A), rdfs_subsumes(A,B).

remove_subsumers_1(_, [], []).

remove_subsumers_1(OriginalList, [Current|ListToProcess], Out) :-
	delete(OriginalList, Current, WithoutCurrent),
	subsumes_from_list(Current, WithoutCurrent), !,
	remove_subsumers_1(OriginalList, ListToProcess, Out).

remove_subsumers_1(OriginalList, [Current|ListToProcess], [Current|Out]) :-
	remove_subsumers_1(OriginalList, ListToProcess, Out).

%% removes from L predicates that are super classes or super roles of other predicates in the list
remove_subsumers(L,Out) :-
	remove_duplicates(L, WithoutDuplicates),
	remove_subsumers_1(WithoutDuplicates, WithoutDuplicates, Out).

subsumes_from_list(_, []) :- fail.
subsumes_from_list(Elem, [H|_]) :- Elem = view(Sup), H = view(Sub), rdfs_subsumes(Sup, Sub), !.
subsumes_from_list(Elem, [H|_]) :- rdfs_subsumes(Elem, H), !.
subsumes_from_list(Elem, [_|T]) :- subsumes_from_list(Elem, T).

%%%%%%%%%% Computation of Datalog Expasions %%%%%%%%%%

expand(call(_), _, _) :- !, fail. % critical !!!

expand(Goal, Goal, _) :- edb(Goal), !. % EDB predicate should not be expanded. They will be defined by the mappings

expand(Goal, Goal, 0) :- !, fail. % this means you reach an IDB predicate, which should not be expanded further

%expand((Goal1,Goal2), (Expansion1, Expansion2), Depth) :-
%    Depth >= 1, Depth_1 is Depth - 1,  expand(Goal1, Expansion1, Depth_1), expand(Goal2, Expansion2, Depth_1).

expand((Goal1,Goal2), (Expansion1, Expansion2), Depth) :-
    expand(Goal1, Expansion1, Depth),
    expand(Goal2, Expansion2, Depth).

expand(Goal, Expansion, Depth) :-
    clause(Goal, Body),  Depth >= 1, Depth_1 is Depth - 1,
    expand(Body, Expansion, Depth_1).

optimized_expand(_, call(_), _, _) :- !, fail. % critical !!!

optimized_expand(_, Goal, Goal, _) :- edb(Goal), !. % EDB predicate should not be expanded. They will be defined by the mappings

optimized_expand(_, Goal, Goal, 0) :- !, fail. % this means you reach an IDB predicate, which should not be expanded further

optimized_expand(OriginalGoal, (Goal1,Goal2), (Expansion1, Expansion2), Depth) :-
    optimized_expand(OriginalGoal, Goal1, Expansion1, Depth),
    optimized_expand(OriginalGoal, Goal2, Expansion2, Depth).

optimized_expand(OriginalGoal, Goal, Expansion, Depth) :-
    clause(Goal, Body),  not(member_seq(OriginalGoal, Body)), Depth >= 1, Depth_1 is Depth - 1,
    optimized_expand(OriginalGoal, Body, Expansion, Depth_1).

subsumption_optimized_expand_0(_, call(_), _, _) :- !, fail. % critical !!!

subsumption_optimized_expand_0(_, Goal, [Goal], _) :- edb(Goal), !. % EDB predicate should not be expanded. They will be defined by the mappings

subsumption_optimized_expand_0(_, Goal, [Goal], 0) :- !, fail. % this means you reach an IDB predicate, which should not be expanded further

subsumption_optimized_expand_0(OriginalGoal, Goal, Expansion, Depth) :-
    expand_0(OriginalGoal, Goal, Body),
    %%
    %% expand first the fresh predicates and then remove subsumers
    %%
    expand_fresh(OriginalGoal, Body, ExpansionOfFresh),
    remove_subsumers(ExpansionOfFresh, Optimized), %print([OptBodySequence]),nl,
	%%
	%% the recursive call
    %%
    Depth >= 1, Depth_1 is Depth - 1,
    subsumption_optimized_expand(OriginalGoal, Optimized, Expansion, Depth_1).

subsumption_optimized_expand(_, [], [], _) :- !.

subsumption_optimized_expand(OriginalGoal, [Goal1|Goal2], Expansions, Depth) :-
    subsumption_optimized_expand_0(OriginalGoal, Goal1, Expansion1, Depth),
    subsumption_optimized_expand(OriginalGoal, Goal2, Expansion2, Depth),
	append(Expansion1, Expansion2, OrigExps), remove_subsumers(OrigExps, Expansions).

expand_fresh(_, [], []) :- !.

expand_fresh(OriginalGoal, [Goal1|Goal2], Expansion) :-
	fresh(Goal1), expand_0(OriginalGoal, Goal1, Body1),
	expand_fresh(OriginalGoal, Goal2, Expansion2),
	append(Body1, Expansion2, Expansion), !.

expand_fresh(OriginalGoal, [Goal1|Goal2], [Goal1|Expansion2]) :-
	expand_fresh(OriginalGoal, Goal2, Expansion2).

%% the basic expand
%% - gets a body of goal
%% - flattens it to a list
%% - checks that the original goal is not the list <-- we bring this check down  ??? TODO check if it's really an optimization
expand_0(OriginalGoal, Goal, Expansion) :-
    clause(Goal, Body), flatten(Body, Expansion), not(member_list(OriginalGoal, Expansion)).

%%%%%%%%%%%%% breadth first expand %%%%%%%%%%%%%
%% slower than the normal one

optimized_bf_expand(_, Goal, Goal, _) :-
	edb_expansions(Goal), !.

optimized_bf_expand(OriginalGoal, Goal, Expansions, Depth) :-
    Depth >= 1, Depth_1 is Depth - 1,
	expand_one_level(OriginalGoal, Goal, FirstLevelExpansion),
	expand_fresh(OriginalGoal, FirstLevelExpansion, ExpansionOfFresh),
    remove_subsumers(ExpansionOfFresh, Optimized),
	optimized_bf_expand(OriginalGoal, Optimized, Expansions, Depth_1).

edb_expansions([]) :- !.
edb_expansions([H|T]) :- edb(H), edb_expansions(T).

bf_expand_0(_, call(_), _) :-
    !, fail. 			%% check here
bf_expand_0(_, Goal, [Goal]) :-
    edb(Goal), !. 		%% check here
bf_expand_0(OriginalGoal, Goal, Expansion) :-
    clause(Goal, Body), flatten(Body, Expansion), not(member_list(OriginalGoal, Expansion)).

expand_one_level(_, [], []) :- !.
expand_one_level(OriginalGoal, [Goal1|Goal2], Expansion) :-
	bf_expand_0(OriginalGoal, Goal1, Body1),
	expand_one_level(OriginalGoal, Goal2, Expansion2),
	append(Body1, Expansion2, Expansion).

%%%%%%%%%%%%% end of breadth first expand %%%%%%%%%%%%%

%expand_list(Goal, GoalAndExpansion, Depth) :- expand(Goal, Expansion, Depth),
%    flatten(Expansion, ExpansionList), GoalAndExpansion = (Goal, ExpansionList).
expand_list(Goal, GoalAndExpansion, Depth) :- optimized_expand(Goal, Goal, Expansion, Depth),
    flatten(Expansion, ExpansionList), GoalAndExpansion = (Goal, ExpansionList).

expand_list_opt(Goal, GoalAndExpansion, Depth) :-
	subsumption_optimized_expand(Goal, [Goal], Expansion, Depth),
    GoalAndExpansion = (Goal, Expansion).

%% breadth first
expand_list_bf(Goal, GoalAndExpansion, Depth) :-
	optimized_bf_expand(Goal, [Goal], Expansion, Depth),
	edb_expansions(Expansion),
    GoalAndExpansion = (Goal, Expansion).

datalog_expansions(P, Depth, Expansions) :-
    findall(Expansion, expand_list(P, Expansion, Depth), IntermediateExpansions),
    remove_equivalent(IntermediateExpansions, Expansions).

datalog_expansions_opt(P, Depth, Expansions) :-
    findall(Expansion, expand_list_opt(P, Expansion, Depth), IntermediateExpansions),
    remove_equivalent(IntermediateExpansions, Expansions).

datalog_expansions_bf(P, Depth, Expansions) :-
    findall(Expansion, expand_list_bf(P, Expansion, Depth), IntermediateExpansions),
    remove_equivalent(IntermediateExpansions, Expansions).

%:- dynamic 'http://www.example.org/fresh#fresh6'/1.
%a

%'http://www.example.org/fresh#fresh6(newconst).

%%%%%%%%%% An instance of a datalog program %%%%%%%%%%

edb(view(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#Article'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#AssistantProfessor'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#AssociateProfessor'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#Book'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#Chair'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#ClericalStaff'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#College'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#ConferencePaper'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#Course'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#Department'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#FullProfessor'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#GraduateStudent'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#JournalArticle'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#Lecturer'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#Man'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#Manual'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#ResearchAssistant'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#ResearchGroup'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#Software'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#Specification'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#SystemsStaff'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#TeachingAssistant'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#TechnicalReport'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#UndergraduateStudent'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#University'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#UnofficialPublication'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#Woman'(_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#emailAddress'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#enrollIn'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#firstName'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#hasDoctoralDegreeFrom'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#hasMajor'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#hasMasterDegreeFrom'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#hasUndergraduateDegreeFrom'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#isAdvisedBy'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#isCrazyAbout'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#isFriendOf'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#isHeadOf'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#isMemberOf'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#isTaughtBy'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#lastName'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#like'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#name'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#publicationAuthor'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#researchInterest'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#subOrganizationOf'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#takesCourse'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#teachingAssistantOf'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#telephone'(_,_)).
idb('http://uob.iodt.ibm.com/univ-bench-dl.owl#worksFor'(_,_)).
idb('http://www.example.org/fresh#fresh1'(_)).
idb('http://www.example.org/fresh#fresh10'(_)).
idb('http://www.example.org/fresh#fresh11'(_)).
idb('http://www.example.org/fresh#fresh12'(_)).
idb('http://www.example.org/fresh#fresh13'(_)).
idb('http://www.example.org/fresh#fresh14'(_)).
idb('http://www.example.org/fresh#fresh2'(_)).
idb('http://www.example.org/fresh#fresh3'(_)).
idb('http://www.example.org/fresh#fresh4'(_)).
idb('http://www.example.org/fresh#fresh5'(_)).
idb('http://www.example.org/fresh#fresh6'(_)).
idb('http://www.example.org/fresh#fresh7'(_)).
idb('http://www.example.org/fresh#fresh8'(_)).
idb('http://www.example.org/fresh#fresh9'(_)).

fresh('http://www.example.org/fresh#fresh1'(_)).
fresh('http://www.example.org/fresh#fresh10'(_)).
fresh('http://www.example.org/fresh#fresh11'(_)).
fresh('http://www.example.org/fresh#fresh12'(_)).
fresh('http://www.example.org/fresh#fresh13'(_)).
fresh('http://www.example.org/fresh#fresh14'(_)).
fresh('http://www.example.org/fresh#fresh2'(_)).
fresh('http://www.example.org/fresh#fresh3'(_)).
fresh('http://www.example.org/fresh#fresh4'(_)).
fresh('http://www.example.org/fresh#fresh5'(_)).
fresh('http://www.example.org/fresh#fresh6'(_)).
fresh('http://www.example.org/fresh#fresh7'(_)).
fresh('http://www.example.org/fresh#fresh8'(_)).
fresh('http://www.example.org/fresh#fresh9'(_)).

'http://uob.iodt.ibm.com/univ-bench-dl.owl#Article'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#Article'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#AssistantProfessor'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#AssistantProfessor'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#AssociateProfessor'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#AssociateProfessor'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Book'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#Book'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Chair'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#Chair'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#ClericalStaff'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#ClericalStaff'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#College'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#College'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#ConferencePaper'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#ConferencePaper'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Course'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#Course'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Department'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#Department'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#FullProfessor'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#FullProfessor'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#GraduateStudent'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#GraduateStudent'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#JournalArticle'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#JournalArticle'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Lecturer'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#Lecturer'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Man'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#Man'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Manual'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#Manual'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#ResearchAssistant'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#ResearchAssistant'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#ResearchGroup'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#ResearchGroup'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Software'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#Software'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Specification'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#Specification'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#SystemsStaff'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#SystemsStaff'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#TeachingAssistant'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#TeachingAssistant'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#TechnicalReport'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#TechnicalReport'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#UndergraduateStudent'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#UndergraduateStudent'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#University'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#University'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#UnofficialPublication'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#UnofficialPublication'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Woman'(X) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#Woman'(X)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#emailAddress'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#emailAddress'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#enrollIn'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#enrollIn'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#firstName'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#firstName'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasDoctoralDegreeFrom'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#hasDoctoralDegreeFrom'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasMajor'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#hasMajor'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasMasterDegreeFrom'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#hasMasterDegreeFrom'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasUndergraduateDegreeFrom'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#hasUndergraduateDegreeFrom'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#isAdvisedBy'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#isAdvisedBy'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#isCrazyAbout'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#isCrazyAbout'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#isFriendOf'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#isFriendOf'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#isHeadOf'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#isHeadOf'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#isMemberOf'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#isMemberOf'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#isTaughtBy'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#isTaughtBy'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#lastName'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#lastName'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#like'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#like'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#name'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#name'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#publicationAuthor'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#publicationAuthor'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#researchInterest'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#researchInterest'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#subOrganizationOf'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#subOrganizationOf'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#takesCourse'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#takesCourse'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#teachingAssistantOf'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#teachingAssistantOf'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#telephone'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#telephone'(X, Y)).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#worksFor'(X, Y) :- view('http://uob.iodt.ibm.com/univ-bench-dl.owl#worksFor'(X, Y)).

'http://uob.iodt.ibm.com/univ-bench-dl.owl#AcademicSubject'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Engineering'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#AcademicSubject'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#FineArts'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#AcademicSubject'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#HumanitiesAndSocial'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#AcademicSubject'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Science'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#AcademicSubject'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasMajor'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Article'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#ConferencePaper'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Article'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#JournalArticle'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Article'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#TechnicalReport'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Chair'(X) :-  'http://www.example.org/fresh#fresh6'(X), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#College'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#WomanCollege'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Course'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#GraduateCourse'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Course'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#listedCourse'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Course'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#teacherOf'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Course'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#teachingAssistantOf'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Dean'(X) :-  'http://www.example.org/fresh#fresh1'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Department'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#enrollIn'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Director'(X) :-  'http://www.example.org/fresh#fresh14'(X), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Employee'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Faculty'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Employee'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X), 'http://www.example.org/fresh#fresh4'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Employee'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#SupportingStaff'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Faculty'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Lecturer'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Faculty'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#PostDoc'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Faculty'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Professor'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Faculty'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isTaughtBy'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#GraduateCourse'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#takesCourse'(X,Y), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#GraduateStudent'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Insterest'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Music'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Insterest'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Sports'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Organization'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#College'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Organization'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Department'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Organization'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Institute'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Organization'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Program'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Organization'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#ResearchGroup'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Organization'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#University'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Organization'(X) :-  'http://www.example.org/fresh#_eliminatedtransfresh_0'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Organization'(X) :-  'http://www.example.org/fresh#_eliminatedtransfresh_2'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Organization'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isAffiliateOf'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Organization'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isAffiliatedOrganizationOf'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Organization'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isAffiliatedOrganizationOf'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Organization'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isMemberOf'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Organization'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isStudentOf'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Organization'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#orgPublication'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Chair'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Dean'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Director'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Employee'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Man'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#PeopleWithHobby'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#ResearchAssistant'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#SportsFan'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#SportsLover'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Student'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#TeachingAssistant'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Woman'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X) :-  'http://www.example.org/fresh#_eliminatedtransfresh_1'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X) :-  'http://www.example.org/fresh#_eliminatedtransfresh_3'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasAlumnus'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasDoctoralDegreeFrom'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasMasterDegreeFrom'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasMember'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasUndergraduateDegreeFrom'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isAdvisedBy'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isAffiliateOf'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isFriendOf'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isFriendOf'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#publicationAuthor'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Professor'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#AssistantProfessor'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Professor'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#AssociateProfessor'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Professor'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Chair'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Professor'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Dean'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Professor'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#FullProfessor'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Professor'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#VisitingProfessor'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Professor'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isAdvisedBy'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Professor'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#tenured'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Publication'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Article'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Publication'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Book'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Publication'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Manual'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Publication'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Software'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Publication'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Specification'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Publication'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#UnofficialPublication'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Publication'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#orgPublication'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Publication'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#publicationAuthor'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Publication'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#publicationDate'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Publication'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#publicationResearch'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Publication'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#softwareDocumentation'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Research'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#publicationResearch'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Research'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#researchProject'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#ResearchGroup'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#researchProject'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Schedule'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#listedCourse'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#ScienceStudent'(X) :-  'http://www.example.org/fresh#fresh7'(X), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#Student'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Software'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#softwareDocumentation'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Software'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#softwareVersion'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#SportsFan'(X) :-  'http://www.example.org/fresh#fresh8'(X), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#SportsLover'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X), 'http://www.example.org/fresh#fresh9'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Student'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#GraduateStudent'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Student'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#NonScienceStudent'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Student'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#ScienceStudent'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Student'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#UndergraduateStudent'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Student'(X) :-  'http://www.example.org/fresh#fresh5'(X), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Student'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasStudent'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Student'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#takesCourse'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#SupportingStaff'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#ClericalStaff'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#SupportingStaff'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#SystemsStaff'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#TeachingAssistant'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X), 'http://www.example.org/fresh#fresh13'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#TeachingAssistant'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#teachingAssistantOf'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#UndergraduateStudent'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasStudent'(X,Y), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#WomanCollege'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#University'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasDegreeFrom'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#University'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasDoctoralDegreeFrom'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#University'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasMasterDegreeFrom'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#University'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasUndergraduateDegreeFrom'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Work'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Course'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#Work'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Research'(X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasAlumnus'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasDoctoralDegreeFrom'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasAlumnus'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasMasterDegreeFrom'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasAlumnus'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasUndergraduateDegreeFrom'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasAlumnus'(Y,X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasDegreeFrom'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasDegreeFrom'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasAlumnus'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasDegreeFrom'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasDoctoralDegreeFrom'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasDegreeFrom'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasMasterDegreeFrom'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasDegreeFrom'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasUndergraduateDegreeFrom'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasMember'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasStudent'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasMember'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isMemberOf'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasMember'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#worksFor'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasSameHomeTownWith'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasSameHomeTownWith'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasSameHomeTownWith'(X,Z) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasSameHomeTownWith'(X,Y), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasSameHomeTownWith'(Y,Z).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasSameHomeTownWith'(Y,X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasSameHomeTownWith'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasStudent'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#enrollIn'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasStudent'(Y,X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isStudentOf'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#isFriendOf'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isFriendOf'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#isFriendOf'(Y,X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isFriendOf'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#isMemberOf'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isStudentOf'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#isMemberOf'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#worksFor'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#isMemberOf'(Y,X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasMember'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#isStudentOf'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#enrollIn'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#isStudentOf'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasStudent'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#isTaughtBy'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#teacherOf'(Y,X).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#like'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isCrazyAbout'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#like'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#love'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#love'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#like'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#subOrganizationOf'(X,Z) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#subOrganizationOf'(X,Y), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#subOrganizationOf'(Y,Z).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#teacherOf'(Y,X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isTaughtBy'(X,Y).
'http://uob.iodt.ibm.com/univ-bench-dl.owl#worksFor'(X,Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isHeadOf'(X,Y).
'http://www.example.org/fresh#_eliminatedtransfresh_0'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#subOrganizationOf'(X,Y).
'http://www.example.org/fresh#_eliminatedtransfresh_0'(Y) :-  'http://www.example.org/fresh#_eliminatedtransfresh_0'(X), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#subOrganizationOf'(X,Y).
'http://www.example.org/fresh#_eliminatedtransfresh_1'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasSameHomeTownWith'(Y,X), 'http://www.example.org/fresh#_eliminatedtransfresh_1'(X).
'http://www.example.org/fresh#_eliminatedtransfresh_1'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasSameHomeTownWith'(Y,X).
'http://www.example.org/fresh#_eliminatedtransfresh_2'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#subOrganizationOf'(Y,X).
'http://www.example.org/fresh#_eliminatedtransfresh_2'(Y) :-  'http://www.example.org/fresh#_eliminatedtransfresh_2'(X), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#subOrganizationOf'(Y,X).
'http://www.example.org/fresh#_eliminatedtransfresh_3'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasSameHomeTownWith'(X,Y), 'http://www.example.org/fresh#_eliminatedtransfresh_3'(X).
'http://www.example.org/fresh#_eliminatedtransfresh_3'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasSameHomeTownWith'(X,Y).
'http://www.example.org/fresh#fresh1'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Dean'(X).
'http://www.example.org/fresh#fresh1'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isHeadOf'(Y,X), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#College'(X).
'http://www.example.org/fresh#fresh10'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasStudent'(X,Y), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#WomanCollege'(X).
'http://www.example.org/fresh#fresh11'(X) :-  'http://www.example.org/fresh#fresh10'(X).
'http://www.example.org/fresh#fresh12'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Person'(X).
'http://www.example.org/fresh#fresh13'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#TeachingAssistant'(X).
'http://www.example.org/fresh#fresh13'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Course'(X), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#teachingAssistantOf'(Y,X).
'http://www.example.org/fresh#fresh14'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Director'(X).
'http://www.example.org/fresh#fresh14'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isHeadOf'(Y,X), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#Program'(X).
'http://www.example.org/fresh#fresh2'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#NonScienceStudent'(X), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasMajor'(X,Y).
'http://www.example.org/fresh#fresh3'(X) :-  'http://www.example.org/fresh#fresh2'(X).
'http://www.example.org/fresh#fresh4'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Chair'(X).
'http://www.example.org/fresh#fresh4'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Dean'(X).
'http://www.example.org/fresh#fresh4'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Director'(X).
'http://www.example.org/fresh#fresh4'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Employee'(X).
'http://www.example.org/fresh#fresh4'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#ResearchAssistant'(X).
'http://www.example.org/fresh#fresh4'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Organization'(X), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#worksFor'(Y,X).
'http://www.example.org/fresh#fresh5'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Student'(X).
'http://www.example.org/fresh#fresh5'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasStudent'(X,Y), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#Organization'(X).
'http://www.example.org/fresh#fresh6'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Chair'(X).
'http://www.example.org/fresh#fresh6'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#isHeadOf'(Y,X), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#Department'(X).
'http://www.example.org/fresh#fresh7'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#ScienceStudent'(X).
'http://www.example.org/fresh#fresh7'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Science'(X), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#hasMajor'(Y,X).
'http://www.example.org/fresh#fresh8'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#SportsFan'(X).
'http://www.example.org/fresh#fresh8'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Sports'(X), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#isCrazyAbout'(Y,X).
'http://www.example.org/fresh#fresh9'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#SportsFan'(X).
'http://www.example.org/fresh#fresh9'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#SportsLover'(X).
'http://www.example.org/fresh#fresh9'(Y) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#like'(Y,X), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#Sports'(X).
'http://www.w3.org/2002/07/owl#Nothing'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Man'(X), 'http://uob.iodt.ibm.com/univ-bench-dl.owl#Woman'(X).
'http://www.w3.org/2002/07/owl#Nothing'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Man'(X), 'http://www.example.org/fresh#fresh11'(X).
'http://www.w3.org/2002/07/owl#Nothing'(X) :-  'http://uob.iodt.ibm.com/univ-bench-dl.owl#Science'(X), 'http://www.example.org/fresh#fresh3'(X).
'http://www.w3.org/2002/07/owl#Nothing'(X) :-  'http://www.example.org/fresh#eliminateMinCard_fresh3'(X), 'http://www.example.org/fresh#eliminateMinCard_fresh5'(X).
'http://www.w3.org/2002/07/owl#Nothing'(X) :-  'http://www.example.org/fresh#eliminateMinCard_fresh4'(X), 'http://www.example.org/fresh#eliminateMinCard_fresh3'(X).
'http://www.w3.org/2002/07/owl#Nothing'(X) :-  'http://www.example.org/fresh#eliminateMinCard_fresh4'(X), 'http://www.example.org/fresh#eliminateMinCard_fresh5'(X).


text:
var AWS = require('aws-sdk');

// Based on:
// https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#listObjectsV2-property

// Usage:
// node experimental-ls.js AWS_KEY AWS_SECRET

var optionalPrefix = process.env.PREFIX || undefined;
var optionalMaxKeys = undefined;
var awsAccessKey = process.argv[2] || process.env.KEY;
var awsSecret = process.argv[3] || process.env.SECRET;
var bucketName = process.env.BUCKET || 'experiment-jun28-2018';

console.log('Using AWS access key:', awsAccessKey);
console.log('Using AWS secret:', awsSecret);
console.log('Using bucket:', bucketName);
console.log('Listing files in S3 with optional prefix:', optionalPrefix);
console.log('Max keys is set to:', optionalMaxKeys);

// var s3 = new AWS.S3({
//   apiVersion: '2006-03-01',
//   region: 'us-west-2',
//   accessKeyId: awsAccessKey,
//   secretAccessKey: awsSecret
// });

// var s3LsArgins = {
//   Bucket: bucketName,
//   MaxKeys: optionalMaxKeys,
//   Prefix: optionalPrefix
// };
// for (let k in s3LsArgins) {
//   if (s3LsArgins[k] === undefined) {
//     delete s3LsArgins[k];
//   }
// }

// s3.listObjectsV2(s3LsArgins, (err, result)=>{
//   if (err){
//     console.error('s3 ls error:',err);
//     return;
//   }

//   console.log('s3 ls success!', result['Contents']);

// });//_∏_

// Or, using adapter:
// ================================================
var adapter = require('../index')({
  bucket: bucketName,
  region: 'us-west-2',
  key: awsAccessKey,
  secret: awsSecret,
});

adapter.ls(optionalPrefix, (err, results)=>{
  if (err) {
    console.error('s3 ls error:', err);
  } else {
    console.log('s3 ls success!', results);
  }
});//_∏_
// ================================================

redpajama_set_name: RedPajamaGithub


text:
<resources>

    <!-- Base application theme. -->
    <style name="MyMaterialTheme" parent="MyMaterialTheme.Base"></style>

    <style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="GeneralButtonStyle">
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">@drawable/button_text_color</item>
        <item name="android:background">@drawable/button_bg_transparent</item>
    </style>

    <style name="InfoButtonStyle">
        <item name="android:textStyle">bold</item>
        <item name="android:layout_width">100dp</item>
        <item name="android:layout_height">75dp</item>
        <item name="android:background">@android:color/transparent</item>
        <item name="android:textColor">@drawable/button_text_color</item>
        <item name="android:textSize">18sp</item>
        <item name="android:text">@string/info</item>
    </style>

    <style name="TextShadow">
        <item name="android:textStyle">bold</item>
        <item name="android:shadowColor">#000000</item>
        <item name="android:shadowDx">2</item>
        <item name="android:shadowDy">2</item>
        <item name="android:shadowRadius">2</item>
        <item name="android:textSize">24sp</item>
        <item name="android:textColor">#FFFFFF</item>
    </style>

    <style name="AchievementColorClicked">
        <item name="android:layout_width">50dp</item>
        <item name="android:layout_height">50dp</item>
        <item name="android:text">Filler Text Here</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">@android:color/white</item>
        <item name="android:gravity">center</item>
        <item name="android:layout_marginBottom">5dp</item>
        <item name="android:layout_marginLeft">5dp</item>
    </style>

    <style name="AchievementColorClickedHardToSee">
        <item name="android:layout_width">50dp</item>
        <item name="android:layout_height">50dp</item>
        <item name="android:text">Filler Text Here</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">@android:color/black</item>
        <item name="android:gravity">center</item>
        <item name="android:layout_marginBottom">5dp</item>
        <item name="android:layout_marginLeft">5dp</item>
    </style>

    <style name="AchievementSectionHeader">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_gravity">center_horizontal</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">18sp</item>
        <item name="android:textColor">@android:color/black</item>
        <item name="android:layout_marginBottom">5dp</item>
        <item name="android:layout_marginLeft">5dp</item>
        <item name="android:layout_marginRight">5dp</item>
    </style>

</resources>


text:
package de.adorsys.cse.jwk;

import java.security.PublicKey;
import java.text.ParseException;
import java.util.IllegalFormatException;

public interface JWKPublicKeyBuilder {
    JWK build(String pemEncodedPublicKey) throws IllegalFormatException;

    JWK build(PublicKey publicKey);

    JWK buildFromBase64EncodedJWK(String base64encodedJWK) throws ParseException;
}


text:
<system>
	<name>WASP-20</name>
	<star>
		<planet>
			<name>WASP-20 b</name>
			<list>Confirmed planets</list>
			<mass>0.3</mass>
			<radius>0.9</radius>
			<period>4</period>
			<description>This planet has been announced at the Extreme Solar Systems II conference in Jackson Hole by the WASP team.</description>
			<discoverymethod>transit</discoverymethod>
			<lastupdate>11/09/13</lastupdate>
			<discoveryyear>2011</discoveryyear>
		</planet>
		<name>WASP-20</name>
		<temperature>5700.0</temperature>
	</star>
</system>


text:
package alotoc.graphics.view;

import java.awt.Color;

import javax.swing.JTextField;

import alotoc.Constants;
import alotoc.logic.PrefMouseListener;

/**
 * This is a Frame for the preferences dialog.
 *
 * @author Kazeheki
 * @see AbstractAlotocFrame
 */
@SuppressWarnings("serial")
public class PrefDialogFrame extends AbstractAlotocFrame {

	/** The input field of this frame. */
	private JTextField inputField;
	/** An instance of this object. */
	private static PrefDialogFrame instance = null;

	/**
	 * Ctor.
	 *
	 * @param x
	 *            X position of frame.
	 * @param y
	 *            Y position of frame.
	 */
	private PrefDialogFrame(final int x, final int y) {
		super(x, y, Constants.PREF_FRM_WIDTH, Constants.PREF_FRM_HEIGHT, "Preferences");
		this.setBackground(new Color(50, 50, 50, 200));
		this.addMouseListener(new PrefMouseListener(this));
		PrefView view = new PrefView(this);
		this.add(view);
		this.inputField = view.getInputField();

		this.setVisible(true);
	}

	/**
	 * Gets an instance of the object. If non is existent, a new one will be
	 * created.
	 *
	 * @param x
	 *            X position of frame.
	 * @param y
	 *            Y position of frame.
	 * @return Instances of object.
	 */
	public static PrefDialogFrame getInstance(final int x, final int y) {
		if (instance == null) {
			instance = new PrefDialogFrame(x, y);
		}

		return instance;
	}

	public static void close(){
		instance = null;
	}

	public final JTextField getInputField() {
		return inputField;
	}
}


text:
package org.keycloak.testsuite.model;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.TargetsContainer;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.keycloak.admin.client.resource.UserResource;
import org.keycloak.common.util.Time;
import org.keycloak.models.*;
import org.keycloak.models.utils.KeycloakModelUtils;
import org.keycloak.models.utils.ResetTimeOffsetEvent;
import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.services.managers.ClientManager;
import org.keycloak.services.managers.RealmManager;
import org.keycloak.sessions.AuthenticationSessionModel;
import org.keycloak.sessions.CommonClientSessionModel;
import org.keycloak.sessions.RootAuthenticationSessionModel;
import org.keycloak.testsuite.AbstractTestRealmKeycloakTest;
import org.keycloak.testsuite.arquillian.annotation.ModelTest;
import org.keycloak.testsuite.runonserver.RunOnServerDeployment;

import java.util.concurrent.atomic.AtomicReference;

import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
import static org.keycloak.testsuite.arquillian.DeploymentTargetModifier.AUTH_SERVER_CURRENT;

/**
 * @author Marek Posolda
 */
public class AuthenticationSessionProviderTest extends AbstractTestRealmKeycloakTest {

    @Deployment
    @TargetsContainer(AUTH_SERVER_CURRENT)
    public static WebArchive deploy() {
        return RunOnServerDeployment.create(UserResource.class, AuthenticationSessionProviderTest.class)
                .addPackages(true,
                        "org.keycloak.testsuite",
                        "org.keycloak.testsuite.model");
    }

    @Before
    public void before() {
        testingClient.server().run(session -> {
            RealmModel realm = session.realms().getRealm("test");
            session.users().addUser(realm, "user1").setEmail("user1@localhost");
            session.users().addUser(realm, "user2").setEmail("user2@localhost");

        });
    }

    @After
    public void after() {
        testingClient.server().run(session -> {
            RealmModel realm = session.realms().getRealm("test");
            session.sessions().removeUserSessions(realm);

            UserModel user1 = session.users().getUserByUsername("user1", realm);
            UserModel user2 = session.users().getUserByUsername("user2", realm);

            UserManager um = new UserManager(session);
            if (user1 != null) {
                um.removeUser(realm, user1);
            }
            if (user2 != null) {
                um.removeUser(realm, user2);
            }
        });
    }

    @Test
    @ModelTest
    public void testLoginSessionsCRUD(KeycloakSession session) {
        AtomicReference<String> rootAuthSessionID = new AtomicReference<>();
        AtomicReference<String> tabID = new AtomicReference<>();

        KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionCRUD1) -> {
            KeycloakSession currentSession = sessionCRUD1;
            RealmModel realm = currentSession.realms().getRealm("test");

            ClientModel client1 = realm.getClientByClientId("test-app");

            RootAuthenticationSessionModel rootAuthSession = currentSession.authenticationSessions().createRootAuthenticationSession(realm);
            rootAuthSessionID.set(rootAuthSession.getId());

            AuthenticationSessionModel authSession = rootAuthSession.createAuthenticationSession(client1);
            tabID.set(authSession.getTabId());

            authSession.setAction("foo");
            rootAuthSession.setTimestamp(100);
        });

        KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionCRUD2) -> {
            KeycloakSession currentSession = sessionCRUD2;
            RealmModel realm = currentSession.realms().getRealm("test");

            ClientModel client1 = realm.getClientByClientId("test-app");

            // Ensure currentSession is here
            RootAuthenticationSessionModel rootAuthSession = currentSession.authenticationSessions().getRootAuthenticationSession(realm, rootAuthSessionID.get());
            AuthenticationSessionModel authSession = rootAuthSession.getAuthenticationSession(client1, tabID.get());
            testAuthenticationSession(authSession, client1.getId(), null, "foo");

            assertThat(rootAuthSession.getTimestamp(), is(100));

            // Update and commit
            authSession.setAction("foo-updated");
            rootAuthSession.setTimestamp(200);
            authSession.setAuthenticatedUser(currentSession.users().getUserByUsername("user1", realm));
        });

        KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionCRUD3) -> {
            KeycloakSession currentSession = sessionCRUD3;
            RealmModel realm = currentSession.realms().getRealm("test");
            UserModel user1 = currentSession.users().getUserByUsername("user1", realm);

            // Ensure currentSession was updated
            RootAuthenticationSessionModel rootAuthSession = currentSession.authenticationSessions().getRootAuthenticationSession(realm, rootAuthSessionID.get());
            ClientModel client1 = realm.getClientByClientId("test-app");
            AuthenticationSessionModel authSession = rootAuthSession.getAuthenticationSession(client1, tabID.get());

            testAuthenticationSession(authSession, client1.getId(), user1.getId(), "foo-updated");

            assertThat(rootAuthSession.getTimestamp(), is(200));

            // Remove and commit
            currentSession.authenticationSessions().removeRootAuthenticationSession(realm, rootAuthSession);
        });

        KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionCRUD4) -> {
            KeycloakSession currentSession = sessionCRUD4;
            RealmModel realm = currentSession.realms().getRealm("test");

            // Ensure currentSession was removed
            assertThat(currentSession.authenticationSessions().getRootAuthenticationSession(realm, rootAuthSessionID.get()), nullValue());
        });
    }

    @Test
    @ModelTest
    public void testAuthenticationSessionRestart(KeycloakSession session) {
        AtomicReference<String> parentAuthSessionID = new AtomicReference<>();
        AtomicReference<String> tabID = new AtomicReference<>();

        KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionRestart1) -> {
            KeycloakSession currentSession = sessionRestart1;
            RealmModel realm = currentSession.realms().getRealm("test");

            ClientModel client1 = realm.getClientByClientId("test-app");
            UserModel user1 = currentSession.users().getUserByUsername("user1", realm);

            AuthenticationSessionModel authSession = currentSession.authenticationSessions().createRootAuthenticationSession(realm)
                    .createAuthenticationSession(client1);

            parentAuthSessionID.set(authSession.getParentSession().getId());
            tabID.set(authSession.getTabId());

            authSession.setAction("foo");
            authSession.getParentSession().setTimestamp(100);

            authSession.setAuthenticatedUser(user1);
            authSession.setAuthNote("foo", "bar");
            authSession.setClientNote("foo2", "bar2");
            authSession.setExecutionStatus("123", CommonClientSessionModel.ExecutionStatus.SUCCESS);
        });

        KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionRestart2) -> {
            KeycloakSession currentSession = sessionRestart2;
            RealmModel realm = currentSession.realms().getRealm("test");

            // Test restart root authentication session
            ClientModel client1 = realm.getClientByClientId("test-app");
            AuthenticationSessionModel authSession = currentSession.authenticationSessions().getRootAuthenticationSession(realm, parentAuthSessionID.get())
                    .getAuthenticationSession(client1, tabID.get());
            authSession.getParentSession().restartSession(realm);
        });

        KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionRestart3) -> {
            KeycloakSession currentSession = sessionRestart3;
            RealmModel realm = currentSession.realms().getRealm("test");

            ClientModel client1 = realm.getClientByClientId("test-app");

            RootAuthenticationSessionModel rootAuthSession = currentSession.authenticationSessions().getRootAuthenticationSession(realm, parentAuthSessionID.get());

            assertThat(rootAuthSession.getAuthenticationSession(client1, tabID.get()), nullValue());
            assertThat(rootAuthSession.getTimestamp() > 0, is(true));
        });
    }

    @Test
    @ModelTest
    public void testExpiredAuthSessions(KeycloakSession session) {
        AtomicReference<String> authSessionID = new AtomicReference<>();

        KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionExpired) -> {
            KeycloakSession mainSession = sessionExpired;
            try {
                // AccessCodeLifespan = 10 ; AccessCodeLifespanUserAction = 10 ; AccessCodeLifespanLogin = 30
                setAccessCodeLifespan(mainSession, 10, 10, 30);

                createAuthSession(mainSession, authSessionID);
                testExpiredOffset(mainSession, 25, false, authSessionID.get());
                testExpiredOffset(mainSession, 35, true, authSessionID.get());

                // AccessCodeLifespan = Not set ; AccessCodeLifespanUserAction = 10 ; AccessCodeLifespanLogin = Not set
                setAccessCodeLifespan(mainSession, -1, 40, -1);

                createAuthSession(mainSession, authSessionID);
                testExpiredOffset(mainSession, 35, false, authSessionID.get());
                testExpiredOffset(mainSession, 45, true, authSessionID.get());

                // AccessCodeLifespan = 50 ; AccessCodeLifespanUserAction = Not set ; AccessCodeLifespanLogin = Not set
                setAccessCodeLifespan(mainSession, 50, -1, -1);

                createAuthSession(mainSession, authSessionID);
                testExpiredOffset(mainSession, 45, false, authSessionID.get());
                testExpiredOffset(mainSession, 55, true, authSessionID.get());

            } finally {
                Time.setOffset(0);
                session.getKeycloakSessionFactory().publish(new ResetTimeOffsetEvent());
                setAccessCodeLifespan(mainSession, 60, 300, 1800);
            }
        });
    }

    @Test
    @ModelTest
    public void testOnRealmRemoved(KeycloakSession session) {
        AtomicReference<String> authSessionID = new AtomicReference<>();
        AtomicReference<String> authSessionID2 = new AtomicReference<>();

        KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sesRealmRemoved1) -> {
            KeycloakSession currentSession = sesRealmRemoved1;
            RealmModel realm = currentSession.realms().getRealm("test");
            RealmModel fooRealm = currentSession.realms().createRealm("foo-realm");

            fooRealm.addClient("foo-client");

            authSessionID.set(currentSession.authenticationSessions().createRootAuthenticationSession(realm).getId());
            authSessionID2.set(currentSession.authenticationSessions().createRootAuthenticationSession(fooRealm).getId());
        });

        KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sesRealmRemoved2) -> {
            KeycloakSession currentSession = sesRealmRemoved2;

            new RealmManager(currentSession).removeRealm(currentSession.realms().getRealmByName("foo-realm"));
        });

        KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sesRealmRemoved3) -> {
            KeycloakSession currentSession = sesRealmRemoved3;
            RealmModel realm = currentSession.realms().getRealm("test");

            RootAuthenticationSessionModel authSession = currentSession.authenticationSessions().getRootAuthenticationSession(realm, authSessionID.get());

            assertThat(authSession, notNullValue());
            assertThat(currentSession.authenticationSessions().getRootAuthenticationSession(realm, authSessionID2.get()), nullValue());
        });
    }

    @Test
    @ModelTest
    public void testOnClientRemoved(KeycloakSession session) {
        AtomicReference<String> tab1ID = new AtomicReference<>();
        AtomicReference<String> tab2ID = new AtomicReference<>();
        AtomicReference<String> authSessionID = new AtomicReference<>();

        KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sesRealmRemoved1) -> {
            KeycloakSession currentSession = sesRealmRemoved1;
            RealmModel realm = currentSession.realms().getRealm("test");

            authSessionID.set(currentSession.authenticationSessions().createRootAuthenticationSession(realm).getId());

            AuthenticationSessionModel authSession1 = currentSession.authenticationSessions().getRootAuthenticationSession(realm, authSessionID.get()).createAuthenticationSession(realm.getClientByClientId("test-app"));
            AuthenticationSessionModel authSession2 = currentSession.authenticationSessions().getRootAuthenticationSession(realm, authSessionID.get()).createAuthenticationSession(realm.getClientByClientId("third-party"));
            tab1ID.set(authSession1.getTabId());
            tab2ID.set(authSession2.getTabId());

            authSession1.setAuthNote("foo", "bar");
            authSession2.setAuthNote("foo", "baz");
        });

        KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sesRealmRemoved1) -> {
            KeycloakSession currentSession = sesRealmRemoved1;
            RealmModel realm = currentSession.realms().getRealm("test");

            RootAuthenticationSessionModel rootAuthSession = currentSession.authenticationSessions().getRootAuthenticationSession(realm, authSessionID.get());

            assertThat(rootAuthSession.getAuthenticationSessions().size(), is(2));
            assertThat(rootAuthSession.getAuthenticationSession(realm.getClientByClientId("test-app"), tab1ID.get()).getAuthNote("foo"), is("bar"));
            assertThat(rootAuthSession.getAuthenticationSession(realm.getClientByClientId("third-party"), tab2ID.get()).getAuthNote("foo"), is("baz"));

            new ClientManager(new RealmManager(currentSession)).removeClient(realm, realm.getClientByClientId("third-party"));
        });

        KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sesRealmRemoved1) -> {
            KeycloakSession currentSession = sesRealmRemoved1;
            RealmModel realm = currentSession.realms().getRealm("test");
            RootAuthenticationSessionModel rootAuthSession = currentSession.authenticationSessions().getRootAuthenticationSession(realm, authSessionID.get());

            assertThat(rootAuthSession.getAuthenticationSession(realm.getClientByClientId("test-app"), tab1ID.get()).getAuthNote("foo"), is("bar"));
            assertThat(rootAuthSession.getAuthenticationSession(realm.getClientByClientId("third-party"), tab2ID.get()), nullValue());

            // Revert client
            realm.addClient("third-party");
        });
    }

    private void testAuthenticationSession(AuthenticationSessionModel authSession, String expectedClientId, String expectedUserId, String expectedAction) {
        assertThat(authSession.getClient().getId(), is(expectedClientId));

        if (expectedUserId == null) {
            assertThat(authSession.getAuthenticatedUser(), nullValue());
        } else {
            assertThat(authSession.getAuthenticatedUser().getId(), is(expectedUserId));
        }

        if (expectedAction == null) {
            assertThat(authSession.getAction(), nullValue());
        } else {
            assertThat(authSession.getAction(), is(expectedAction));
        }
    }

    private void createAuthSession(KeycloakSession session, AtomicReference<String> authSessionID) {

        KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession createAuthSession) -> {
            KeycloakSession currentSession = createAuthSession;
            RealmModel realm = currentSession.realms().getRealm("test");

            Time.setOffset(0);
            authSessionID.set(currentSession.authenticationSessions().createRootAuthenticationSession(realm).getId());
        });
    }

    private void testExpiredOffset(KeycloakSession session, int offset, boolean isSessionNull, String authSessionID) {

        KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionExp) -> {
            KeycloakSession currentSession = sessionExp;
            RealmModel realm = currentSession.realms().getRealm("test");

            Time.setOffset(offset);
            currentSession.authenticationSessions().removeExpired(realm);
        });

        KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionExpVerify) -> {
            KeycloakSession currentSession = sessionExpVerify;
            RealmModel realm = currentSession.realms().getRealm("test");

            if (isSessionNull)
                assertThat(currentSession.authenticationSessions().getRootAuthenticationSession(realm, authSessionID), nullValue());
            else
                assertThat(currentSession.authenticationSessions().getRootAuthenticationSession(realm, authSessionID), notNullValue());
        });
    }

    // If parameter is -1, then the parameter won't change.
    private void setAccessCodeLifespan(KeycloakSession session, int lifespan, int lifespanUserAction, int lifespanLogin) {

        KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionLifespan) -> {
            KeycloakSession currentSession = sessionLifespan;
            RealmModel realm = currentSession.realms().getRealm("test");

            if (lifespan != -1)
                realm.setAccessCodeLifespan(lifespan);

            if (lifespanUserAction != -1)
                realm.setAccessCodeLifespanUserAction(lifespanUserAction);

            if (lifespanLogin != -1)
                realm.setAccessCodeLifespanLogin(lifespanLogin);
        });
    }

    @Override
    public void configureTestRealm(RealmRepresentation testRealm) {
    }
}


text:
/

#if (_MSC_VER > 1000) || defined(SGI_COMPILER)
#pragma once
#endif

//*********************************************************************************************
//
//
//*********************************************************************************************

#ifndef __DSSTLMFC_H__
#define __DSSTLMFC_H__

// resolve min/max conflict between windef.h and STL
#ifdef min
	#undef min
	#define MIN_WAS_DEFINED
#endif
#ifdef max
	#undef max
	#define MAX_WAS_DEFINED
#endif

// To avoid including <bool.h>
#ifndef _BOOL
#define _BOOL
#endif

// C++ header files
#include <new.h>
#include <iostream.h>
#include <fstream.h>

//******************************************************************************
//
// Use the SGI Adapted Port STL Implementation
//
//******************************************************************************

#include <algorithm>
#include <deque>
#include <functional>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

// some backwards compatibility
#define __BEGIN_STL_NAMESPACE	__STL_BEGIN_NAMESPACE
#define __END_STL_NAMESPACE		__STL_END_NAMESPACE

// use only with the unix STL
#ifdef sgi
// A more user friendly define for the namespace name
# define _STL             std
// They changed the namespace define from std to __STD
# define __STL            __STD
# define std  __STD
#endif

// warning, an "#include <math.h>" unref the macros min and max
#define max(a,b)		(((a) > (b)) ? (a) : (b))
#define min(a,b)		(((a) < (b)) ? (a) : (b))

// Done include STL headers
#define __STL_OUTERMOST_HEADER_ID 0

#endif /* __DSSTLMFC_H__ */


text:
package com.linkedin.pinot.query.aggregation;

import static org.testng.Assert.assertEquals;

import com.clearspring.analytics.stream.cardinality.HyperLogLog;
import com.linkedin.pinot.core.query.aggregation.function.*;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.*;

import com.linkedin.pinot.util.TestUtils;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import org.apache.commons.collections.ListUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.linkedin.pinot.common.request.AggregationInfo;
import com.linkedin.pinot.core.query.aggregation.AggregationFunction;
import com.linkedin.pinot.core.query.aggregation.CombineLevel;

/**
 *
 * Tests for DistinctCountHLL estimation, the rountine is similar to {@link SimpleAggregationFunctionsTest}
 *
 *
 */
public class DistinctCountHLLTest {
    private static final Logger LOGGER = LoggerFactory.getLogger(DistinctCountHLLTest.class);

    public static int[] _docIdsArray;
    public static IntArray _docIds;
    public static int _sizeOfDocIdArray = 5000;
    public static String _columnName = "met";
    public static AggregationInfo _paramsInfo;

    private static final int DUPLICATION_PER_ITEM = 1000;

    @BeforeClass
    public static void setup() {
        _docIdsArray = new int[_sizeOfDocIdArray];
        for (int i = 0; i < _sizeOfDocIdArray; ++i) {
            _docIdsArray[i] = i;
        }
        _docIds = new DefaultIntArray(_docIdsArray);
        Map<String, String> params = new HashMap<String, String>();
        params.put("column", _columnName);
        _paramsInfo = new AggregationInfo();
        _paramsInfo.setAggregationType("");
        _paramsInfo.setAggregationParams(params);

    }

    public static class RandomNumberArray {
        // For test purpose, we fix the random seeds.
        // It should also work for arbitrary seeds like System.currentTimeMillis()
        private static Random _rnd = new Random(0L);

        private final Integer[] arr;
        private final HashSet<Integer> set = new HashSet<Integer>();

        /**
         * Data ranges between [0, size)
         * @param size
         * @param duplicationPerItem
         */
        public RandomNumberArray(int size, int duplicationPerItem) {
            List<Integer> lst = new ArrayList<Integer>();
            for (int i = 0; i < size/duplicationPerItem; i++) {
                Integer item = _rnd.nextInt(size);
                for (int j = 0; j < duplicationPerItem; j++) {
                    lst.add(item); // add duplicates
                }
            }
            // add remaining items
            int st = lst.size();
            for (int i = st; i < size; i++) {
                Integer item = _rnd.nextInt(size);
                lst.add(item);
            }
            // add to set
            set.addAll(lst);
            // shuffle
            Collections.shuffle(lst, new Random(10L));
            // toIntArray
            arr = lst.toArray(new Integer[0]);
            if (arr.length != size) {
                throw new RuntimeException("should not happen");
            }
        }

        public int size() {
            return arr.length;
        }

        public int getPreciseCardinality() {
            return set.size();
        }

        public void offerAllNumberTo(HyperLogLog hyperLogLog) {
            offerNumberInRangeTo(hyperLogLog, 0, arr.length);
        }

        public void offerAllNumberTo(IntOpenHashSet hashSet) {
            offerNumberInRangeTo(hashSet, 0, arr.length);
        }

        public void offerNumberInRangeTo(HyperLogLog hyperLogLog, int start, int end) {
            end = Math.min(end, arr.length);
            for (int i = start; i < end; i++) {
                hyperLogLog.offer(arr[i]);
            }
        }

        public void offerNumberInRangeTo(IntOpenHashSet hashSet, int start, int end) {
            end = Math.min(end, arr.length);
            for (int i = start; i < end; i++) {
                hashSet.add(arr[i]);
            }
        }
    }

    @Test
    public void testDistinctCountHLLAggregation() {
        AggregationFunction aggregationFunction = new DistinctCountHLLAggregationFunction();
        aggregationFunction.init(_paramsInfo);

        // Test aggregate

        // Test combine
        int _sizeOfCombineList = 1000;
        StringBuilder sb1 = new StringBuilder();
        StringBuilder sb2 = new StringBuilder();
        for (int i = 1; i <= _sizeOfCombineList; ++i) {
            List<Serializable> aggregationResults = getHLLResultValues(i);
            List<Serializable> combinedResult = aggregationFunction.combine(aggregationResults, CombineLevel.SEGMENT);
            long estimate = ((HyperLogLog) (combinedResult.get(0))).cardinality();
            TestUtils.assertApproximation(estimate, i, 0.1);
            sb1.append(estimate + ", ");
            sb2.append(i + ", ");
        }
        // assertEquals(sb1.toString(), sb2.toString());  // assert actual equals (nearly impossible!)

        // Test reduce
        for (int i = 1; i <= _sizeOfCombineList; ++i) {
          List<Serializable> combinedResults = getHLLResultValues(i);
          long reduceSize = (Long) aggregationFunction.reduce(combinedResults);
          TestUtils.assertApproximation(reduceSize, i, 0.1);
        }
    }

    @Test
    public void testDistinctCountHLLRandomAggregationLarge() {
        AggregationFunction aggregationFunction = new DistinctCountHLLAggregationFunction();
        aggregationFunction.init(_paramsInfo);

        // Test aggregate

        // Test combine
        // Make combine list number fixed to 10, each list has large number of elements
        int maxSize = 100000; // 10000000
        for (int i = 1; i <= maxSize; i += maxSize/17) {
            if (i==1) continue;
            RandomNumberArray arr = new RandomNumberArray(i*10, 1);
            long t1 = System.nanoTime();
            List<Serializable> aggregationResults = getHLLRandomResultValues(arr, 10, i);
            long t2 = System.nanoTime();
            List<Serializable> combinedResult = aggregationFunction.combine(aggregationResults, CombineLevel.SEGMENT);
            long t3 = System.nanoTime();
            long estimate = ((HyperLogLog) (combinedResult.get(0))).cardinality();
            long precise = arr.getPreciseCardinality();
            println(i + ", " + "" + (t2 - t1) + "" + ", " + (t3 - t2) + ", " + getErrorString(precise, estimate));
            TestUtils.assertApproximation(estimate, precise, 0.1);
        }

        // Test reduce
        /*for (int i = 1; i <= _sizeOfCombineList; ++i) {
          List<Serializable> combinedResults = getHLLResultValues(i);
          long reduceSize = (Long) aggregationFunction.reduce(combinedResults);
          assertApproximation(reduceSize, i, 1.1);
        }*/
    }

    @Test
    public void testDistinctCountHLLRandomAggregationCombine() {
        AggregationFunction hllAggregationFunction = new DistinctCountHLLAggregationFunction();
        hllAggregationFunction.init(_paramsInfo);
        AggregationFunction setAggregationFunction = new DistinctCountAggregationFunction();
        setAggregationFunction.init(_paramsInfo);

        final int numOfItemsPerList = 100;
        final int numOfListCombined = 100000;
        println("#list_combined, HLL_time(nano), IntOpenHashSet(nano), time_ratio, estimate, precise, error");
        // Test combine
        StringBuilder sb1 = new StringBuilder();
        StringBuilder sb2 = new StringBuilder();
        for (int i = 1; i <= numOfListCombined; i+=numOfListCombined/17) {
            if (i == 1) {
                continue;
            }
            RandomNumberArray arr = new RandomNumberArray(i*numOfItemsPerList, DUPLICATION_PER_ITEM);

            List<Serializable> hllAggregationResults = getHLLRandomResultValues(arr, i, numOfItemsPerList);
            long t1 = System.nanoTime();
            List<Serializable> hllCombinedResult = hllAggregationFunction.combine(hllAggregationResults, CombineLevel.SEGMENT);
            long t2 = System.nanoTime();

            List<Serializable> setAggregationResults = getIntOpenHashSets(arr, i, numOfItemsPerList);
            long t3 = System.nanoTime();
            List<Serializable> setCombinedResult = setAggregationFunction.combine(setAggregationResults, CombineLevel.SEGMENT);
            long t4 = System.nanoTime();

            long estimate = ((HyperLogLog) (hllCombinedResult.get(0))).cardinality();
            long precise = arr.getPreciseCardinality();

            println(i + ", " + (t2 - t1) + ", " + (t4 - t3) + ", " + (t2 - t1 + 0.0) / (t4 - t3 + 0.0) + ", "
                    + estimate + ", " + precise + ", " + getErrorString(precise, estimate));
            TestUtils.assertApproximation(estimate, precise, 0.15);
            assertEquals(((IntOpenHashSet) (setCombinedResult.get(0))).size(), precise);
        }
    }

    @Test
    public void testInsertionTime() {
        int numOfItems = 10000000;

        println("#items_inserted, HLL_time(nano), IntOpenHashSet(nano), time_ratio, estimate, precise, error");
        for (int i = 0; i < numOfItems; i+=numOfItems/17) {
            if (i == 0) {
                continue;
            }
            RandomNumberArray arr = new RandomNumberArray(i, DUPLICATION_PER_ITEM);
            HyperLogLog hllResult = new HyperLogLog(DistinctCountHLLAggregationFunction.DEFAULT_BIT_SIZE);
            IntOpenHashSet set = new IntOpenHashSet(); //HashSet<Integer> set = new HashSet<Integer>();
            long t1 = System.nanoTime();
            arr.offerAllNumberTo(hllResult);
            long t2 = System.nanoTime();
            arr.offerAllNumberTo(set);
            long t3 = System.nanoTime();
            long estimate = hllResult.cardinality();
            long precise = set.size();
            println(i + ", " + "" + (t2 - t1) + ", " + (t3 - t2) + ", " + (t2 - t1 + 0.0) / (t3 - t2 + 0.0) + ", "
                    + estimate + ", " + precise + ", " + getErrorString(precise, estimate));
        }
        assertEquals(true, true);
    }

    @Test
    public void testMemoryConsumption() {
        int numOfItems = 10000000;

        println("#items_inserted, HLL_ser_size, openHashSet_ser_size, ser_size_ratio, estimate, precise, error");
        for (int i = 0; i < numOfItems; i+=numOfItems/17) {
            if (i == 0) {
                continue;
            }
            RandomNumberArray arr = new RandomNumberArray(i, DUPLICATION_PER_ITEM);
            HyperLogLog hllResult = new HyperLogLog(DistinctCountHLLAggregationFunction.DEFAULT_BIT_SIZE);
            IntOpenHashSet set = new IntOpenHashSet();
            arr.offerAllNumberTo(hllResult);
            arr.offerAllNumberTo(set);
            int hllSize = getSerializedSize(hllResult);
            int setSize = getSerializedSize(set);
            long estimate = hllResult.cardinality();
            long precise = set.size();
            println(i + ", " + hllSize + ", " + setSize + ", " + (hllSize + 0.0) / (setSize + 0.0) + ", "
                    + estimate + ", " + precise + ", " + getErrorString(precise, estimate));
        }
        assertEquals(true, true);
    }

    // ------------ helper functions ------------

    private void println(String s) {
        LOGGER.debug(s);
    }

    private String getErrorString(long precise, long estimate) {
        if (precise != 0) {
            return Math.abs((precise - estimate + 0.0) / precise) * 100 + "%";
        } else {
            return "precise: " + precise + " estimate: " + estimate;
        }
    }

    private int getSerializedSize(Serializable ser) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = null;
        try {
            oos = new ObjectOutputStream(baos);
            oos.writeObject(ser);
            oos.close();
            return baos.size();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return -1;
    }

    private static List<Serializable> getHLLResultValues(int numberOfElements) {
        List<Serializable> hllResultList = new ArrayList<Serializable>();
        for (int i = 0; i < numberOfElements; ++i) {
            HyperLogLog hllResult = new HyperLogLog(DistinctCountHLLAggregationFunction.DEFAULT_BIT_SIZE);
            hllResult.offer(i);
            hllResultList.add(hllResult);
        }
        return hllResultList;
    }

    private static List<Serializable> getHLLRandomResultValues(RandomNumberArray arr, int numOfListCombined, int numOfItemsPerList) {
        List<Serializable> hllResultList = new ArrayList<Serializable>();
        for (int i = 0; i < numOfListCombined; ++i) {
            HyperLogLog hllResult = new HyperLogLog(DistinctCountHLLAggregationFunction.DEFAULT_BIT_SIZE);
            arr.offerNumberInRangeTo(hllResult, i*numOfItemsPerList, (i+1)*numOfItemsPerList);
            hllResultList.add(hllResult);
        }
        return hllResultList;
    }

    private static List<Serializable> getIntOpenHashSets(RandomNumberArray arr, int numberOfListCombined, int numOfItemsPerList) {
        List<Serializable> intOpenHashSets = new ArrayList<Serializable>();
        for (int i = 0; i < numberOfListCombined; ++i) {
            IntOpenHashSet intOpenHashSet = new IntOpenHashSet();
            arr.offerNumberInRangeTo(intOpenHashSet, i*numOfItemsPerList, (i+1)*numOfItemsPerList);
            intOpenHashSets.add(intOpenHashSet);
        }
        return intOpenHashSets;
    }
}


text:
import unittest
import time
import traceback

import ClydeLog

class ClydeTestCase(unittest.TestCase):
  def __init__(self, methodName):
    super(ClydeTestCase, self).__init__(methodName)
    self.log = ClydeLog.getLogger()

  def run(self, result=None):
		if result.failures or result.errors:
			self.log.info(self.id() + " ABORTED")
		else:
			super(ClydeTestCase, self).run(result)

class ClydeTestRunner():
  def __init__(self, id):
    self.log = ClydeLog.getLogger()
    self.testid = id

  def run(self, name, test):
    self.log.info("START RUN: %s" % name)
    result = ClydeTestResult()
    startTime = time.time()
    test(result)
    stopTime = time.time()

    timeTaken = stopTime - startTime
    run = result.testsRun
    self.log.info("Ran %d test%s in %.3fs" % (run, run != 1 and "s" or "", timeTaken))
    if not result.wasSuccessful():
      failed, errored = map(len, (result.failures, result.errors))
      self.log.error("END RUN (failed: %d, errors: %d) TEST #%d\n" % (failed, errored, self.testid))
    else:
      self.log.success("END RUN: ALL OK! TEST #%d\n" % (self.testid))
    return result

class ClydeTestResult(unittest.TestResult):
  def __init__(self):
    unittest.TestResult.__init__(self)
    self.log = ClydeLog.getLogger()

  def startTest(self, test):
    unittest.TestResult.startTest(self, test)
    self.log.info(test.id().split('.')[-1] + " STARTED")

  def stopTest(self, test):
    self.log.info(test.id().split('.')[-1] + " STOP")
    #self.shouldStop = test.stopTests

  def addSuccess(self, test):
    unittest.TestResult.addSuccess(self, test)
    self.log.info(test.id().split('.')[-1] + " PASS")

  def addError(self, test, err):
    unittest.TestResult.addError(self, test, err)
    t, formatted_err = self.errors[-1]
    self.log.info(test.id().split('.')[-1] + " ERROR " + formatted_err.splitlines()[-1])

  def addFailure(self, test, err):
    unittest.TestResult.addFailure(self, test, err)
    t, formatted_err = self.failures[-1]
    self.log.info(test.id().split('.')[-1] + " FAILURE " + formatted_err.splitlines()[-1])


text:
using System;
using System.Reflection;
using System.Resources;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("Klinkby.Calendar")]
[assembly: AssemblyDescription("General logic for handling time slots in a calendar.")]

#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
#else
[assembly: AssemblyConfiguration("Release")]
#endif

[assembly: AssemblyCompany("Mads Klinkby")]
[assembly: AssemblyProduct("Klinkby")]
[assembly: AssemblyCopyright("Copyright © Mads Breusch Klinkby 2015")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.1")]
[assembly: ComVisible(false)]
[assembly: CLSCompliant(true)]


text:
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p10/procedures/hwp/io/p10_io_iohs_firmask_save_restore.H $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2021                             */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

/// @file p10_io_iohs_firmask_save_restore.H
/// @brief HWP that allows caller to save off cross-node IOHS
///        (and associated PAUC) FIR masks into attributes for later restoration
///        and mask off cross-node errors during that time.
//-----------------------------------------------------------------------------
// *HWP HW  Owner        : Chris Steffen    <cwsteffen@us.ibm.com>
// *HWP HW  Backup Owner :
// *HWP FW Owner         : Nick Bofferding <bofferdn@us.ibm.com>
// *HWP Team             : IO
// *HWP Level            : 3
// *HWP Consumed by      : HB
// EKB-Mirror-To: hostboot
//-----------------------------------------------------------------------------

#ifndef _P10_IO_IOHS_FIRMASK_SAVE_RESTORE_H
#define _P10_IO_IOHS_FIRMASK_SAVE_RESTORE_H

//------------------------------------------------------------------------------
//  System Header Include
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//  fapi2 Includes
//------------------------------------------------------------------------------
#include <fapi2.H>

//------------------------------------------------------------------------------
//  Definitions
//------------------------------------------------------------------------------

namespace p10iofirmasksaverestore
{

/**
* @brief Operation Type (Save or Restore)
*/
enum OP_TYPE
{
    SAVE      = 0x0,
    RESTORE   = 0x1,
};

} // namespace p10iofirmasksaverestore

typedef fapi2::ReturnCode (*p10_io_iohs_firmask_save_restore_FP_t)(const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>&,
        const p10iofirmasksaverestore::OP_TYPE);

extern "C"
{
    /**
    *     @brief This hardware procedure takes a processor chip and an OP_TYPE
    *     enum as arguments.  IF OP_TYPE is SAVE, the procedure walks every IOHS
    *     in the processor involved in a cross-node bus connection (i.e. an IOHS
    *     whose ATTR_IOHS_CONFIG_MODE attribute is
    *     ENUM_ATTR_IOHS_CONFIG_MODE_SMPA) and saves off its DLP_FIR_MASK_REG
    *     and its parent PAUC's PB_PTL_FIR_MASK_REG register values into
    *     attributes, then masks off FIR bits in those registers to prevent
    *     escalation of various cross-node bus failures.  If OP_TYPE is RESTORE,
    *     the procedure restores attribute values back into the registers from
    *     which they came, thereby restoring the original FIR masks.
    *
    *     Hostboot must call this procedure during MPIPL time with an OP_TYPE of
    *     SAVE in order to suppress cross-node bus errors since during that
    *     time, each nodal Hostboot instance has no visibility to the others.
    *     If PRD were to handle a cross-node bus error, it would not be able to
    *     resolve the other end of the bus and make appropriate callouts.   The
    *     masking must be done as soon as Hostboot has resolved the targets in
    *     the node, i.e. in host_discover_targets.
    *
    *     At runtime after an MPIPL, HBRT must call this HWP again after
    *     initializing targeting (after which targeting has awareness of all
    *     nodes) with the RESTORE OP_TYPE in order to restore the original FIR
    *     mask values, so that PRD will once again process all the cross-node
    *     errors as appropriate. There should only be one single HWP call with
    *     the RESTORE flag for every call invoked with the SAVE flag.
    *
    *     Note: If this HWP is called with the SAVE op then after storing the
    *           FIR masks into attributes, it will mask off additional bits in
    *           the FIRs.
    *
    *     PowerBus Transaction Layer FIR0 Mask Register
    *     10011803 = PB.PTLSCOM10.PB_PTL_FIR_MASK_REG (base register; applies to
    *     all PAUC)
    *     10011804 = PB.PTLSCOM10.PB_PTL_FIR_MASK_REG_WO_AND
    *     10011805 = PB.PTLSCOM10.PB_PTL_FIR_MASK_REG_WO_OR
    *
    *       Register:Bit           IOHS Child (Even unit/Odd unit)
    *       ======================================================
    *       DOB01_ERR_MASK:7       Even
    *       DOB23_ERR_MASK:11      Odd
    *       PARSER00_ATTN_MASK:18  Even
    *       PARSER01_ATTN_MASK:19  Even
    *       PARSER02_ATTN_MASK:20  Odd
    *       PARSER03_ATTN_MASK:21  Odd
    *       DIB01_ERR_MASK:26      Even
    *       DIB23_ERR_MASK:27      Odd
    *
    *     PowerBus DLP FIR Mask Register
    *     18011003 = DLP0.DLP.DLP_FIR_MASK_REG (base register; applies to all
    *     IOHS)
    *     18011004 = DLP0.DLP.DLP_FIR_MASK_REG_WO_AND
    *     18011005 = DLP0.DLP.DLP_FIR_MASK_REG_WO_OR
    *
    *       Register:Bit
    *       ===========================================
    *       FIR_LINK0_NO_SPARE_MASK:42
    *       FIR_LINK1_NO_SPARE_MASK:43
    *       FIR_LINK0_SPARE_DONE_MASK:44
    *       FIR_LINK1_SPARE_DONE_MASK:45
    *       FIR_LINK0_TOO_MANY_CRC_ERRORS_MASK:46
    *       FIR_LINK1_TOO_MANY_CRC_ERRORS_MASK:47
    *       FIR_LINK0_CORRECTABLE_ARRAY_ERROR_MASK:52
    *       FIR_LINK1_CORRECTABLE_ARRAY_ERROR_MASK:53
    *       FIR_LINK0_UNCORRECTABLE_ARRAY_ERROR_MASK:54
    *       FIR_LINK1_UNCORRECTABLE_ARRAY_ERROR_MASK:55
    *       FIR_LINK0_TRAINING_FAILED_MASK:56
    *       FIR_LINK1_TRAINING_FAILED_MASK:57
    *       FIR_LINK0_UNRECOVERABLE_ERROR_MASK:58
    *       FIR_LINK1_UNRECOVERABLE_ERROR_MASK:59
    *
    *     @param[in] i_target_chip   Processor targeted for the FIR
    *         mask save/restore operation
    *     @param[in] i_op            OP_TYPE that caller wishes to perform
    *        (SAVE or RESTORE)
    *
    *     @retval ReturnCode
    */
    fapi2::ReturnCode p10_io_iohs_firmask_save_restore(const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>& i_target_chip,
            const p10iofirmasksaverestore::OP_TYPE i_op);
} //extern "C"

#endif // _P10_IO_IOHS_FIRMASK_SAVE_RESTORE_H


text:
/*
   @ROLEID = { 0 READERS, 1 USERS, 2 MANAGERS}
*/
CREATE FUNCTION [dbo].[netsqlazman_CheckStorePermissions](@STOREID int, @ROLEID tinyint)
RETURNS bit
AS
BEGIN
DECLARE @RESULT bit
IF @STOREID IS NULL OR @ROLEID IS NULL
	SET @RESULT = 0
ELSE
BEGIN
	IF EXISTS (
		SELECT     dbo.[netsqlazman_StorePermissionsTable].StoreId
		FROM         dbo.[netsqlazman_ApplicationsTable] RIGHT OUTER JOIN
		                      dbo.[netsqlazman_StoresTable] ON dbo.[netsqlazman_ApplicationsTable].StoreId = dbo.[netsqlazman_StoresTable].StoreId LEFT OUTER JOIN
		                      dbo.[netsqlazman_StorePermissionsTable] ON dbo.[netsqlazman_StoresTable].StoreId = dbo.[netsqlazman_StorePermissionsTable].StoreId LEFT OUTER JOIN
		                      dbo.[netsqlazman_ApplicationPermissionsTable] ON dbo.[netsqlazman_ApplicationsTable].ApplicationId = dbo.[netsqlazman_ApplicationPermissionsTable].ApplicationId
		WHERE
		IS_MEMBER('db_owner')=1 OR IS_MEMBER('NetSqlAzMan_Administrators')=1 OR
		(@ROLEID = 0 AND IS_MEMBER('NetSqlAzMan_Readers')=1 OR
		@ROLEID = 1 AND IS_MEMBER('NetSqlAzMan_Users')=1 OR
		@ROLEID = 2 AND IS_MEMBER('NetSqlAzMan_Managers')=1) AND
		(
		(dbo.[netsqlazman_StorePermissionsTable].StoreId = @STOREID AND dbo.[netsqlazman_StorePermissionsTable].NetSqlAzManFixedServerRole >= @ROLEID AND
		(SUSER_SNAME(SUSER_SID())=[netsqlazman_StorePermissionsTable].SqlUserOrRole AND [netsqlazman_StorePermissionsTable].IsSqlRole = 0 OR
		IS_MEMBER([netsqlazman_StorePermissionsTable].SqlUserOrRole)=1 AND [netsqlazman_StorePermissionsTable].IsSqlRole = 1)) OR

		(@ROLEID = 0 AND dbo.[netsqlazman_StoresTable].StoreId = @STOREID AND dbo.[netsqlazman_ApplicationPermissionsTable].NetSqlAzManFixedServerRole >= @ROLEID AND
		(SUSER_SNAME(SUSER_SID())=[netsqlazman_ApplicationPermissionsTable].SqlUserOrRole AND [netsqlazman_ApplicationPermissionsTable].IsSqlRole = 0
		OR IS_MEMBER([netsqlazman_ApplicationPermissionsTable].SqlUserOrRole)=1 AND [netsqlazman_ApplicationPermissionsTable].IsSqlRole = 1))))
	SET @RESULT = 1
	ELSE
	SET @RESULT = 0
END
RETURN @RESULT
END

GO
GRANT EXECUTE
    ON OBJECT::[dbo].[netsqlazman_CheckStorePermissions] TO [NetSqlAzMan_Readers]
    AS [dbo];


text:
#ifndef __LOAN_BOOKS_LIST_H
 #define __LOAN_BOOKS_LIST_H

 #include "konias.h"
 #include "ktv.h"

 class LoanBooksList : public TListBox {
	public:
		TUnsortedCollection *loanIds;

		LoanBooksList(const TRect& bounds, ushort aNumCols, TScrollBar *aScrollBar);
		void handleEvent(TEvent& event);
		void setData(void *data);
		void showCurrentLoan();
 };

#endif


text:
title:  Daily Lesson
date:   29/04/2017
---

### We are working on this lesson
Please come back later