comment(Q, F, C) :-
	(   rdfq(Q, F, dc:description, literal(Text))
	;   rdfq(Q, F, rdfs:comment, literal(Text))
	),
	truncated(Text, 250, C).
comment(_Q, _F, em('(No description or comment available.)')).

uses(Q, Focus, HTree) :-
	setofsome(5, _Done, User,
		(   term_source(Focus, User),
		    User \= user,
		    \+rdfpage_uri(User)
		),
		Users),
	/*
	sort(Users, SortedUsers),
	length(SortedUsers, UsesCount),
	(   UsesCount > 5
	->  list_truncate(SortedUsers, 5, SomeSortedUsers),
	    End='...' 
	;   SomeSortedUsers = SortedUsers,
	    End=''
	),
	(   UsesCount=1 -> S='' ; S='s' ),
	HTree =     p(span(class=usesCount, int(UsesCount), ' use', S, ' found: '),
		      +thing_list(Q, SomeSortedUsers),
		      End
		      ). */
	HTree =  p(span(class=usesCount, ' Some uses: '),
		      +thing_list(Q, Users)).
	  
uses(_, p(strong('no external uses found.'))).

/*
list_truncate(X, N, X) :-
	length(X, L),
	L =< N.
list_truncate(All, N, Some) :-
	length(All, Max),
	ResultLength is min(N, Max),
	append(Some, _LeftOver, All),
	length(Some, ResultLength).
*/

%
%  quick sketch of subclass logic; we'll want much better soon, of course 
%

subclass(Q, Sub, Super) :-
	atom(Sub),
	rdfq(Q, Sub, rdfs:subClassOf, Super).
		  
proper_subclass(Q, Sub, Super) :-
	subclass(Q, Sub, Super),
	\+ subclass(Q, Super, Sub).

class(Q, F, C) :-
	atom(F),
	rdfq(Q, F, rdf:type, C),
	atom(C).
class(Q, F, C) :-
	atom(F),
	rdfq(Q, F, rdf:type, C1),
	atom(C1),
	subclass(Q, C1, C).

leaf_class(Q, Focus, Class) :-
	class(Q, Focus, Class),
	\+ proper_subclass(Q, _, Class).

safe_leaf_class(Q, Focus, Class) :-
	call_with_depth_limit(leaf_class(Q, Focus, Class), 6, _Deepest).


notProperSuperClassOfElement(Q, List, This) :-
	\+ (   member(X, List),
	       proper_subclass(Q, X, This)
	   ).
leaf_classes(Q, Focus, HTree) :-
	setofsome(20, _, Class, class(Q, Focus, Class), AllClasses),
	sort(AllClasses, SortedClasses),
	sublist(notProperSuperClassOfElement(Q, SortedClasses), SortedClasses, Classes),
	Classes \= [],
	HTree = +thing_list(Q, Classes).
leaf_classes(_Q, _Focus, em('no class information')).

% html_view('Summary', para, 'http://www.w3.org/2000/01/rdf-schema#', [], HTree).

is_rdf_property(Q, X) :-
	rdfq(Q, X, rdf:type, rdfs:'Property').
is_rdf_property(Q, X) :-
	rdfq(Q, X, rdf:type, rdf:'Property').
is_rdf_property(Q, X) :-
	rdfq(Q, X, rdf:type, owl:'ObjectProperty').
is_rdf_property(Q, X) :-
	rdfq(Q, X, rdf:type, owl:'FunctionalProperty').
is_rdf_property(Q, X) :-
	rdfq(Q, X, rdf:type, owl:'InverseFunctionalProperty').
is_rdf_property(Q, X) :-
	rdfq(Q, X, rdf:type, owl:'DatatypeProperty').
is_rdf_property(Q, X) :-
	rdfq(Q, X, rdfs:subPropertyOf, _).
is_rdf_property(Q, X) :-
	rdfq(Q, _, rdfs:subPropertyOf, X).
is_rdf_property(Q, X) :-
	rdfq(Q, _, X, _).

is_rdf_class(Q, X) :-
	rdfq(Q, X, rdf:type, rdfs:'Class').
is_rdf_class(Q, X) :-
	rdfq(Q, X, rdf:type, owl:'Class').
is_rdf_class(Q, X) :-
	rdfq(Q, X, rdfs:subClassOf, _).
is_rdf_class(Q, X) :-
	rdfq(Q, _, rdfs:subClassOf, X).
is_rdf_class(Q, X) :-
	rdfq(Q, _, rdf:type, X).

term_defined(Term, Ontology) :-
	rdf_split_url(NS, _Local, Term),
	sub_atom(NS, _, 1, 0, LastChar),
	sub_atom(NS, 0, _, 1, Chopped),
	(   LastChar = '#'
	->  Ontology=Chopped
	;   (   address_latest_successful_ret(Chopped, Ret)
	    ->  ret_get(Ret, retr:finalResource, Ontology)
	    ;   Ontology=Chopped
	    )
	).

term_defined_in(Q, Focus, ['defined in ', +word(Q, Ont)]) :-
	term_defined(Focus, Ont).

%para(Q, Focus, 	+rdfs_property_view(Q, Focus)) :-
%	is_rdf_property(Q, Focus).
para(Q, Focus, HTree) :-
	% member(linkParaHeading, Q)
	comment(Q, Focus, SummaryText),
	HTree = div(class=summary,
		    div(class=siteControls, a(href=Focus, 'Visit')),
		    h2(class=summaryTitle,
		       +word(Q, Focus),
		       span(class=summaryTitleComment,
			    +leaf_classes(Q, Focus))),
			    %', ',
			    %+term_defined_in(Q, Focus))),
		    p(class=summaryText, SummaryText),
		    % +para_on_deref_status(Q, Focus),
		    +uses(Q, Focus)
		   ).

/*
    		      a(href='x', 'sdfsdf:', '(host, defn)'),
		      a(href='x', 'sdf:', '(host)'),

  */

/*
html_view('X View', para, Focus, Q, HTree) :-
	atom(Focus),
	findall(
		span('has ', +word(Q, P), ' ', +word(Q, O), '; '),
		(says(Focus, P, O,  _)),
		Out),
	self_uri(basic, Q, [focus=Focus], Link, ""),
	% how do you take the first 6 items in a list?!
	(  [T1, T2, T3, T4, T5, _ | _] = Out,
	   [T1, T2, T3, T4, T5, a(href=Link, 'more...') ] = Out1
	;  Out = Out1
	),
	(  Out1 = [_|_]
	-> Comments = [  '  (Which ', Out1, ')']
	;  Comments = [  '  (no more info in cache)']
	),
	HTree = span(strong(a(href=Link, +word(Q, Focus))), Comments).
	
html_view('X View', para, Focus, Q, HTree) :-
	\+ atom(Focus),
	short(Q, Focus, HTree, []), !.

*/