Index: /SMC/trunk/SMC/src/xsl/dcr_dcif2terms.xsl
===================================================================
--- /SMC/trunk/SMC/src/xsl/dcr_dcif2terms.xsl	(revision 6834)
+++ /SMC/trunk/SMC/src/xsl/dcr_dcif2terms.xsl	(revision 6835)
@@ -41,15 +41,23 @@
  -->
  
- <!--  handling compressed dcif-format 
- 	<dcif:dataCategory definition="start time of recording" identifier="recordingTime"
- 	name="recording time" owner="Reichel, Uwe" pid="http://www.isocat.org/datcat/DC-4521"
- 	type="complex" version="1:0">
- 	<dcif:conceptualDomain type="constrained">
- 	<dcif:dataType>string</dcif:dataType>
- 	<dcif:ruleType>XML Schema regular expression</dcif:ruleType>
- 	<dcif:rule>([01][0-9]|2[0-4]):[0-5][0-9]:[0-5][0-9]</dcif:rule>
- 	</dcif:conceptualDomain>
- 	</dcif:dataCategory> 	
- -->
+
+	<xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
+		<xd:desc>
+			<xd:p>handling compressed dcif-format</xd:p>
+			<xd:pre>
+				 	<dcif:dataCategory definition="start time of recording" identifier="recordingTime"
+				 	name="recording time" owner="Reichel, Uwe" pid="http://www.isocat.org/datcat/DC-4521"
+				 	type="complex" version="1:0">
+				 	<dcif:conceptualDomain type="constrained">
+				 	<dcif:dataType>string</dcif:dataType>
+				 	<dcif:ruleType>XML Schema regular expression</dcif:ruleType>
+				 	<dcif:rule>([01][0-9]|2[0-4]):[0-5][0-9]:[0-5][0-9]</dcif:rule>
+				 	</dcif:conceptualDomain>
+				 	</dcif:dataCategory> 	
+			</xd:pre>
+		</xd:desc>
+		
+		<xd:param name="set">the set from which the concept is coming (only valid value: 'isocat' (?))</xd:param>
+	</xd:doc>
 <xsl:template match="dcif:dataCategory[@name]" >
 	<xsl:param name="set" />
@@ -76,5 +84,11 @@
 </xsl:template>
 
- <!--  handling full dcif-format -->
+	<xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
+		<xd:desc>
+			<xd:p>handling full dcif-format </xd:p>
+			<xd:p>TODO: should process all ocurring languages</xd:p>
+		</xd:desc>
+		<xd:param name="set"></xd:param>
+	</xd:doc>
 <xsl:template match="dcif:dataCategory" >
 	<xsl:param name="set" />
@@ -104,4 +118,7 @@
 	<Concept type="datcat" id="{@pid}" datcat-type="{@type}">
 		<Term set="{$set}" type="mnemonic" >			 
+			<xsl:value-of select=".//dcif:identifier" />			
+		</Term>
+		<Term set="{$set}" type="mnemonic" xml:lang="{($n/*/xs:string(@xml:lang),$lang)[1]}" >			 
 			<xsl:value-of select="$n" />
 		</Term>
Index: /SMC/trunk/SMC/src/xsl/graph2json-d3.xsl
===================================================================
--- /SMC/trunk/SMC/src/xsl/graph2json-d3.xsl	(revision 6834)
+++ /SMC/trunk/SMC/src/xsl/graph2json-d3.xsl	(revision 6835)
@@ -98,4 +98,8 @@
         <xsl:text>, "value":</xsl:text>
         <xsl:value-of select="@value"/>
+        <xsl:if test="exists(@weight)" >
+           <xsl:text>, "weight":</xsl:text>
+           <xsl:value-of select="@weight"/>
+        </xsl:if>
 <!--        <xsl:text>{"source":"</xsl:text><xsl:value-of select="@from" /><xsl:text>", "target":"</xsl:text><xsl:value-of select="@to" /><xsl:text>", "value":</xsl:text><xsl:value-of select="$count" />-->
         <xsl:text>}</xsl:text>
Index: /SMC/trunk/SMC/src/xsl/smc2stats_datasets.xsl
===================================================================
--- /SMC/trunk/SMC/src/xsl/smc2stats_datasets.xsl	(revision 6834)
+++ /SMC/trunk/SMC/src/xsl/smc2stats_datasets.xsl	(revision 6835)
@@ -24,5 +24,5 @@
  
 
-<xsl:import href="smc_commons.xsl"/>
+<xsl:import href="smc_commons_vars.xsl"/>
 
 	<xsl:output method="xml" indent="yes" />
@@ -30,4 +30,6 @@
   <xsl:param name="title" select="'SMC Stats'" />
 
+  <xsl:param name="parts" select="'overall,profiles,components,datcats,ambigue-terms,list'" />
+	
 	<!--
 		
@@ -71,9 +73,9 @@
 	<xsl:template match="/">
 		<multiresult>
-	        <xsl:call-template name="summary-overall"></xsl:call-template>
-			<xsl:call-template name="summary-profiles"></xsl:call-template>
-			<xsl:call-template name="summary-components"></xsl:call-template>
-			<xsl:call-template name="summary-datcats"></xsl:call-template>
-			<xsl:call-template name="ambigue-terms"></xsl:call-template>
+			<xsl:if test="contains($parts, 'overall')" ><xsl:call-template name="summary-overall"></xsl:call-template></xsl:if>
+			<xsl:if test="contains($parts, 'profiles')" ><xsl:call-template name="summary-profiles"></xsl:call-template></xsl:if>
+			<xsl:if test="contains($parts, 'components')" ><xsl:call-template name="summary-components"></xsl:call-template></xsl:if>
+			<xsl:if test="contains($parts, 'datcats')" ><xsl:call-template name="summary-datcats"></xsl:call-template></xsl:if>
+			<xsl:if test="contains($parts, 'ambigue-terms')" ><xsl:call-template name="ambigue-terms"></xsl:call-template></xsl:if>
 		</multiresult>
 <!--		<xsl:call-template name="summary-concepts"></xsl:call-template>
@@ -99,5 +101,5 @@
 			<ds:label key="elems-without-datcats">Elements without DatCats</ds:label>
 			<ds:label key="elems-without-datcats-ratio" >ratio of elements without DatCats</ds:label>			
-<!--			<ds:label key="distinct-datcats">distinct used Data Categories</ds:label>-->			
+			<ds:label key="distinct-datcats">distinct used Data Categories</ds:label>			
 			<ds:label key="used-concepts">used Concept</ds:label>
 			<ds:label key="available-concepts">available Concepts (in Metadata profile or used in CMD)</ds:label>
@@ -120,5 +122,5 @@
 			<ds:value key="elems-without-datcats-ratio" formatted="{format-number($elems-distinct-without-datcats-ratio, '0.00 %')}">
 				<xsl:value-of select="$elems-distinct-without-datcats-ratio"/></ds:value>
-<!--			<ds:value key="distinct-datcats"><xsl:value-of select="$count_distinct_datcats"/></ds:value>-->
+			<ds:value key="distinct-datcats"><xsl:value-of select="$count_distinct_datcats"/></ds:value>
 			<ds:value key="used-concepts"><xsl:value-of select="count($dcr-cmd-map//Concept)"/></ds:value>
 <!--			<ds:value key="blind-concepts"><xsl:value-of select="count(//Concept[not(Term[@set='isocat'])])"/></ds:value>-->
@@ -213,10 +215,12 @@
 	    			<xsl:with-param name="key">distinct-datcats</xsl:with-param>
 	    			<xsl:with-param name="type">datcat</xsl:with-param>
-	    			<xsl:with-param name="data" select="distinct-values(./Term[@type='CMD_Element']/@datcat[not(.='')])"></xsl:with-param>
+<!--	    			<xsl:with-param name="data" select="distinct-values(./Term[@type='CMD_Element']/@datcat[not(.='')])"></xsl:with-param>-->
+	    			<xsl:with-param name="data" select="distinct-values(./Term/data(@datcat[not(.='')]))"></xsl:with-param>
 	    		</xsl:call-template>
 	    		
-<!--	    		<ds:value key=""><xsl:value-of select="$count_distinct_datcats"/></ds:value>-->
+<!--	    		<ds:value key=""><xsl:value-of select="$count_distinct_datcats"/></ds:value>-->	    		
 	    		<ds:value key="elems-with-datcats"><xsl:value-of select="count(./Term[@type='CMD_Element']/@datcat[not(.='')])"/></ds:value>
 	    		<ds:value key="elems-without-datcats"><xsl:value-of select="count(./Term[@type='CMD_Element'][@datcat=''])"/></ds:value>
+<!--	    		<ds:value key="comp-with-datcats"><xsl:value-of select="count(./Term[@type='CMD_Components']/@datcat[not(.='')])"/></ds:value>-->
 		    	<xsl:variable name="elems-without-datcats-ratio" select="if($count_elems &gt; 0) then count(./Term[@type='CMD_Element'][@datcat='']) div $count_elems else 0"></xsl:variable>
 	    		<ds:value key="elems-without-datcats-ratio" formatted="{format-number($elems-without-datcats-ratio, '0.00 %')}">
@@ -283,5 +287,7 @@
 			id="#applicationType">AnnotationTool.applicationType</Term>-->
 		<xsl:for-each select="$dcr-cmd-map//Concept" >		          
-			<xsl:sort select="lower-case(Term[@type='label'][1])" order="ascending"/>
+<!--			<xsl:sort select="lower-case(Term[@type=('label','mnemonic')][1])" order="ascending"/>-->
+			<xsl:sort select="count(distinct-values(Term[@type='full-path']/@schema))" data-type="number" order="descending"/>
+			
 			
 			<xsl:variable name="def" select="$dcr-terms//Concept[@id=current()/@id]/info[1]" ></xsl:variable>
@@ -289,8 +295,8 @@
 			<xsl:variable name="profiles" select="distinct-values(Term[@type='full-path']/@schema)" ></xsl:variable>
 			
-			<ds:dataseries key="{@id}" label="{Term[@type='label'][1]}" >
+			<ds:dataseries key="{@id}" label="{concat(Term[@type=('label','mnemonic')][1],' [', my:shortURL(@id), ']')}" >
 				<!--		    	<ds:value key="distinct-components"><xsl:value-of select="$count_distinct_components"/></ds:value>-->
 				
-				<ds:value key="def"><xsl:value-of select="$def"/></ds:value>
+				<ds:value key="def"><xsl:value-of select="$def"/></ds:value>				
 				<xsl:call-template name="list">
 					<xsl:with-param name="key" >used-in-profiles</xsl:with-param>
@@ -423,5 +429,4 @@
 <xsl:param name="type" ></xsl:param>
 <xsl:param name="data" ></xsl:param>
-	
 	<xsl:variable name="processed_data">
 		<xsl:choose>
@@ -474,12 +479,15 @@
 	</xsl:variable>
 	<ds:value key="{$key}" abs="{count($processed_data/*)}" >
-		<ds:list>
-			<xsl:for-each select="$processed_data/*" >
-				<xsl:sort select="lower-case(.)" ></xsl:sort>
-				<!--<xsl:variable name="profile-name" select="$all_profiles[@id=current()]/@name"></xsl:variable>-->
-<!--				<li><a href="#{.}" ><xsl:value-of select="$profile-name" /></a></li>-->
-					<xsl:copy-of select="."></xsl:copy-of>
-			</xsl:for-each>
-		</ds:list>
+		<xsl:if test="contains($parts,'list')" >
+			
+			<ds:list>
+				<xsl:for-each select="$processed_data/*" >
+					<xsl:sort select="lower-case(.)" ></xsl:sort>
+					<!--<xsl:variable name="profile-name" select="$all_profiles[@id=current()]/@name"></xsl:variable>-->
+	<!--				<li><a href="#{.}" ><xsl:value-of select="$profile-name" /></a></li>-->
+						<xsl:copy-of select="."></xsl:copy-of>
+				</xsl:for-each>
+			</ds:list>
+		</xsl:if>
 	</ds:value>
 </xsl:template>
Index: /SMC/trunk/SMC/src/xsl/smc_commons.xsl
===================================================================
--- /SMC/trunk/SMC/src/xsl/smc_commons.xsl	(revision 6834)
+++ /SMC/trunk/SMC/src/xsl/smc_commons.xsl	(revision 6835)
@@ -69,6 +69,6 @@
                     <xsl:with-param name="message">getData writing to: <xsl:value-of select="$cache_path"></xsl:value-of></xsl:with-param>							
                 </xsl:call-template>
-                
-             <xsl:result-document href="{$cache_path}" format="xml" >
+                 
+             <xsl:result-document href="{$cache_path}" format="xml"  >
                  <xsl:sequence select="$result" />
              </xsl:result-document>
Index: /SMC/trunk/SMC/src/xsl/terms2graph.xsl
===================================================================
--- /SMC/trunk/SMC/src/xsl/terms2graph.xsl	(revision 6834)
+++ /SMC/trunk/SMC/src/xsl/terms2graph.xsl	(revision 6835)
@@ -26,5 +26,5 @@
     </xd:doc>
 
-    <xsl:output method="xml" encoding="utf-8"/>
+    <xsl:output method="xml" encoding="utf-8" indent="yes"/>
 
     <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
@@ -34,8 +34,10 @@
             <xd:p>recognized values: collections,components,profile-groups,datcats,relations (delimited by ',')</xd:p>            
             <xd:p>if datcats and no components - direct links between profiles and datcats are generated</xd:p>
+            <xd:p>if no datcats and no components - direct links between profiles are generated (weighted by the number of shared data categories</xd:p>
             <xd:p>profile-groups generates extra nodes grouping profiles by metadata (creatore, groupName, domainName)</xd:p>
         </xd:desc>
     </xd:doc>
 <!--        <xsl:param name="parts" select="'profile-groups'"/>-->
+    <xsl:param name="debug" select="false()"/>
     <xsl:param name="parts" select="'collections,profile-groups,components,datcats,relations'"/>
     <xsl:variable name="parts-sequence" select="tokenize($parts,',')"></xsl:variable>
@@ -47,4 +49,12 @@
     </xd:doc>
     <xsl:param name="profiles" select="''"/>  <!--teiHeader-->
+    
+    <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
+        <xd:desc>
+            <xd:p>threshold for the similarity quotient (matched_datcats : profile_terms), when linking profiles (mode=edges-profiles)</xd:p>
+        </xd:desc>
+    </xd:doc>
+    <xsl:param name="match_threshold" select="0.5"/>
+    
 
 
@@ -110,4 +120,6 @@
     </xd:doc>
     <xsl:key name="cmd-terms-path" match="Term" use="@path"/>
+    
+    <xsl:key name="cmd-terms-datcat" match="Term" use="@datcat"/>
 
     <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
@@ -207,4 +219,5 @@
             <xsl:if test="'datcats' = $parts-sequence and 'components' = $parts-sequence" ><xsl:apply-templates select="$enriched-termsets//Term" mode="edges-datcats"/></xsl:if>
             <xsl:if test="'datcats' = $parts-sequence and not('components' = $parts-sequence)" ><xsl:apply-templates select="$enriched-termsets//Term" mode="edges-profiles-datcats"/></xsl:if>
+            <xsl:if test="not('datcats' = $parts-sequence) and not('components' = $parts-sequence)" ><xsl:apply-templates select="$enriched-termsets//Termset[@type='CMD_Profile']" mode="edges-profiles"/></xsl:if>
             <xsl:if test="'relations' = $parts-sequence" ><xsl:apply-templates select="$rr-relations//Relation" mode="edges-rels"/></xsl:if>            
             <xsl:if test="'profile-groups' = $parts-sequence">
@@ -221,13 +234,15 @@
         <xsl:variable name="distinct-edges">
             <xsl:for-each-group select="$edges/*" group-by="concat(@from, @to)">
-                <xsl:variable name="count" select="count(current-group())"/>
+                <xsl:variable name="value" select="if (exists(@value)) then sum(@value) else count(current-group())"/>
+                <xsl:variable name="weight" select="if (exists(@weight)) then sum(@weight) else 1"/>
                 <xsl:variable name="ix_from" select="$distinct-nodes/*[@key=current()/@from]/@position - 1 "/>
                 <xsl:variable name="ix_to" select="$distinct-nodes/*[@key=current()/@to]/@position - 1"/>
-                <edge ix_from="{$ix_from}" ix_to="{$ix_to}" from="{@from}" to="{@to}" value="{$count}"/>
+                <edge ix_from="{$ix_from}" ix_to="{$ix_to}" from="{@from}" to="{@to}" value="{$value}" weight="{$weight}"/>
             </xsl:for-each-group>
         </xsl:variable>
         <xsl:variable name="graph">
             <graph>
-                <nodes count="{count($filtered-termsets//Term)}">
+<!--                <nodes count="{count($filtered-termsets//Term)}">-->
+           <nodes count="{count($distinct-nodes)}">
                     
 <!--                                                            <xsl:copy-of select="$dcr-terms-copy"/>-->
@@ -237,5 +252,5 @@
                 <edges>
                     <xsl:copy-of select="$distinct-edges"/>
-<!--                    <debug><xsl:copy-of select="$edges"/></debug>-->
+                    <xsl:if test="$debug"><debug><xsl:copy-of select="$edges"/></debug></xsl:if>
                 </edges>
             </graph>
@@ -256,5 +271,5 @@
         
         <xsl:variable name="current_profile_key" select="my:normalize(@id)"/>
-        <node id="{@id}" key="{$current_profile_key}" name="{@name}" type="Profile" level="0" count="{@count}" path="{@path}">
+        <node id="{@id}" key="{$current_profile_key}" name="{@name}" type="Profile" level="0" count="{(@count, count(.//Term))[1]}" path="{@path}">
             <!--       <xsl:value-of select="$equivalent_schema_term"></xsl:value-of>-->
         </node>
@@ -262,5 +277,5 @@
         <xsl:if test="xs:string(@id) ne Term/xs:string(@id)">
             <xsl:for-each select="Term">
-                <node id="{@id}" key="{my:normalize(@id)}" name="{@name}" type="Component" level="1" count="{@count}" path="{@path}"/>
+                <node id="{@id}" key="{my:normalize(@id)}" name="{@name}" type="Component" level="1" count="{(@count, count(.//Term))[1]}" path="{@path}"/>
             </xsl:for-each>
         </xsl:if>
@@ -470,4 +485,53 @@
         <xsl:variable name="current_profile_key" select="my:normalize(ancestor::Termset/@id)"/>
         <edge from="{$current_profile_key}" to="{my:normalize(@datcat)}"/>
+    </xsl:template>
+
+    <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
+        <xd:desc>
+            <xd:p>create direct links between profiles based on shared Datcats</xd:p>
+        </xd:desc>
+    </xd:doc>
+    <xsl:template match="Termset[@type='CMD_Profile']" mode="edges-profiles">
+        <xsl:variable name="current_profile_key" select="my:normalize(@id)"/>
+        <xsl:variable name="current_profile_name" select="@name"/>
+        <xsl:variable name="profile_datcats" select="distinct-values(.//Term/data(@datcat)[not(.='')])"/>
+        <xsl:variable name="profile_terms" select=".//Term/data(@id)"/>
+<!--        <edge from="{$current_profile_key}" weight="{count($profile_datcats)}"/>-->
+        <xsl:for-each select="following-sibling::Termset" >
+            <xsl:variable name="other_profile_key" select="my:normalize(@id)"/>
+            <xsl:variable name="matching_datcats" select="distinct-values(.//Term[not(@datcat='')][@datcat=$profile_datcats]/data(@datcat))"/>
+            <xsl:variable name="other_datcats" select="distinct-values(.//Term[not(@datcat='')]/data(@datcat))"/>
+            <xsl:variable name="matching_terms" select="distinct-values(.//Term[@id=$profile_terms]/data(@id))"/>
+            <!--<xsl:variable name="matching_datcats">            
+                <xsl:copy-of select=".//Term[key('cmd-terms-datcat',$profile_datcats)]"/>            
+            </xsl:variable>-->
+<!--            <xsl:if test="exists($matching_datcats)" > -->
+            <xsl:variable name="match_quotient1" select="if (exists($profile_datcats)) then count($matching_datcats) div count($profile_datcats) else 0 " />
+            <xsl:variable name="match_quotient2" select="if (exists($other_datcats)) then count($matching_datcats) div count($other_datcats) else 0" />
+            <xsl:variable name="match_quotient" select="number(($match_quotient1 + $match_quotient2) div 2)" />
+            
+            <xsl:if test="number($match_quotient) &gt; number($match_threshold)" >
+            <!--<xsl:if test="not(number($match_quotient) = number($match_quotient))" >  
+            <xsl:message>DEBUG: <xsl:value-of select="$match_quotient"></xsl:value-of> </xsl:message>
+            </xsl:if>-->
+<!--                weight="{count($matching_datcats) + count($matching_terms)}"-->
+                <edge from="{$current_profile_key}" to="{$other_profile_key}"
+                    from_name="{$current_profile_name}" to_name="{data(@name)}"
+                    value="{count($matching_datcats)}"
+                    weight="{$match_quotient}"                    
+                    count_matching_distinct_terms="{count($matching_terms)}" match_quotient="{$match_quotient}"
+                    count_matching_datcats="{count($matching_datcats)}" 
+                    count_profile_datcats="{count($profile_datcats)}"
+                    count_other_datcats="{count($other_datcats)}"
+                    count_terms="{count($profile_terms)}"
+                    count_other_terms="{count(.//Term)}"
+                    >
+                   <!--DEBUG:
+                       <xsl:copy-of select="$matching_datcats"></xsl:copy-of>-->
+               </edge>
+            </xsl:if>
+            
+        </xsl:for-each>
+        
     </xsl:template>
     
