Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Feb 1, 2018
2 parents aae0a5f + 652acca commit 6fb7f02
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/jpeek/App.java
Expand Up @@ -66,6 +66,11 @@
* to reports list.
* (details on how to test the metrics are to be negotiated here - #107)
*
* @todo #17:30min MWE metric has impediments (see puzzles in MWE.xml).
* Once they are resolved, cover the metric with autotests and add it
* to reports list.
* (details on how to test the metrics are to be negotiated here - #107)
*
* @todo #15:30min LORM metric has impediments (see puzzles in LORM.xml).
* Once they are resolved, cover the metric with autotests and add it
* to reports list.
Expand Down
104 changes: 104 additions & 0 deletions src/main/resources/org/jpeek/metrics/MWE.xsl
@@ -0,0 +1,104 @@
<?xml version="1.0"?>
<!--
The MIT License (MIT)
Copyright (c) 2017-2018 Yegor Bugayenko
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="skeleton">
<metric>
<xsl:apply-templates select="@*"/>
<title>MWE</title>
<description>
<xsl:text><![CDATA[
MWE = max( Oi * Di )
where:
Oi = sum( Pdi ) / n: Occupancy of topic i in a class;
Di = sum( -Qdi * log(Qdi) ) / log(n): Distribution of topic i in a class;
Qdi = Pdi / sum( Pdi ): distribution of topic i in a method d;
Pdi - probability of topic i in a method d;
n - number of methods.
]]></xsl:text>
</description>
<xsl:apply-templates select="node()"/>
</metric>
</xsl:template>
<xsl:template match="class">
<!--
@todo #17:30min The current implementation of MWE metric expects information
about LDA topics and their probability in skeleton.xml by xpath `class/methods/method/topics/topic`.
`topic` items must have two mandatory attributes - `@name` (topic unique identifier) and `@p` (probability of the
topic's occurence in the method). Currently this part of information is missing in skeleton.xml.
Ensure that the core part of JPeek provides the information about topics and their probability
and update the metric in accordance with the provided XML structure.
-->
<xsl:variable name="n" select="count(methods/method)"/>
<xsl:variable name="Oi">
<xsl:for-each-group select="methods/method/topics/topic" group-by="@name">
<xsl:variable name="topic" select="current-grouping-key()"/>
<oi topic="{$topic}" value="{sum(current-group()/@p) div $n}"/>
</xsl:for-each-group>
</xsl:variable>
<xsl:variable name="Qdi">
<xsl:variable name="cur" select="."/>
<xsl:for-each-group select="methods/method" group-by="@name">
<xsl:variable name="method" select="current-grouping-key()"/>
<xsl:for-each-group select="current-group()/topics/topic" group-by="@name">
<xsl:variable name="topic" select="current-grouping-key()"/>
<xsl:variable name="pdi" select="$cur/methods/method[@name=$method]/topics/topic[@name=$topic]/@p"/>
<xsl:variable name="pdSum" select="sum($cur/methods/method/topics/topic[@name=$topic]/@p)"/>
<qdi method="{$method}" topic="{$topic}" value="{$pdi div $pdSum}"/>
</xsl:for-each-group>
</xsl:for-each-group>
</xsl:variable>
<xsl:variable name="Di">
<!--
@todo #17:30min Di value is supposed to be calculated by formula:
Di = sum( -Qdi * log(Qdi) ) / log(n).
See the MWE metric description for details.
However, logarithm function is currently not available in XSL, that's why it is stubbed.
Ensure that there is a way to define logarithm in metrics XSL and unstub Di calculation.
-->
<xsl:variable name="cur" select="."/>
<xsl:for-each-group select="$Qdi/qdi" group-by="@topic">
<di topic="{current-grouping-key()}" value="1.0"/>
</xsl:for-each-group>
</xsl:variable>
<xsl:variable name="OiDi">
<xsl:for-each select="$Oi/oi">
<xsl:variable name="topic" select="@topic"/>
<xsl:variable name="Di" select="$Di/di[@topic=$topic]/@value"/>
<xsl:variable name="Oi" select="$Oi/oi[@topic=$topic]/@value"/>
<oidi v="{$Di * $Oi}"/>
</xsl:for-each>
</xsl:variable>
<xsl:copy>
<xsl:attribute name="value" select="max($OiDi/oidi/@v)"/>
<xsl:apply-templates select="@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

3 comments on commit 6fb7f02

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 6fb7f02 Feb 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 17-e0265053 discovered in src/main/java/org/jpeek/App.java and submitted as #143. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but
we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 6fb7f02 Feb 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 17-049820b6 discovered in src/main/resources/org/jpeek/metrics/MWE.xsl and submitted as #144. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but
we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 6fb7f02 Feb 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 17-f82757ae discovered in src/main/resources/org/jpeek/metrics/MWE.xsl and submitted as #145. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but
we discovered it only now.

Please sign in to comment.