top of page

Levenshtein Solution 1 source code

 

public class solution {

                public static void main(String[] args) {

                                if (args.length < 2) {

                                                System.err.println("Too less arguments");

                                                return;

                                }

                                String s1 = args[0].toLowerCase(), s2 = args[1].toLowerCase();

                                System.out.println("String1: " + s1 + "\nString2: " + s2);

                                int width = s1.length(), height = s2.length();

                                int[][] matrix = new int[width + 1][height + 1];

                                int val = 0, cost = 0;

 

                                for (int y = 0; y <= height; y++) {

                                                for (int x = 0; x <= width; x++) {

                                                                // init

                                                                if (x == 0 && y == 0)

                                                                                val = 0;

                                                                // init

                                                                else if (x == 0)

                                                                                val = matrix[x][y - 1] + 1;

                                                                // init

                                                                else if (y == 0)

                                                                                val = matrix[x - 1][y] + 1;

                                                                else {

                                                                                // check letters

                                                                                if (s1.substring(x - 1, x).compareTo(s2.substring(y - 1, y)) == 0)

                                                                                                cost = 0;

                                                                                else

                                                                                                cost = 1;

 

                                                                                // take minimum

                                                                                val = Math.min(matrix[x - 1][y - 1] + cost,

                                                                                                                Math.min(matrix[x - 1][y] + 1, matrix[x][y - 1] + 1));

                                                                }

                                                                matrix[x][y] = val;

                                                                System.out.print(matrix[x][y] + " ");

                                                }

                                                System.out.println("\n");

                                }

                                System.out.println("Distance is: " + matrix[width][height]);

 

                }

}

 

Annotation in text format

 

File Name >> solution6.java

File Creation data >> 1425000729037

Java Classes --> solution

Method Name --> main

Method return type --> void

 

Annotation in RDF format

 

<rdf:RDF

    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"

    xmlns:SEO="http://www.seontology.org/activeseo/seo/v1#"

    xmlns:DC="http://purl.org/dc/dcmitype/"

    xmlns:foaf="http://xmlns.com/foaf/0.1/">

  <DC:Software rdf:about="http://www.seontology.org/activeseo/seoanno/data/main/Parameter_1">

    <SEO:isParamArray>true</SEO:isParamArray>

    <SEO:paramType>java.lang.String</SEO:paramType>

    <SEO:paramName>args</SEO:paramName>

    <SEO:paramSeq>1</SEO:paramSeq>

    <foaf:name>args</foaf:name>

    <rdf:type rdf:resource="http://www.seontology.org/activeseo/seo/v1#PARAMETER"/>

  </DC:Software>

  <SEO:METHOD rdf:about="http://www.seontology.org/activeseo/seoanno/data/main">

    <SEO:methodHasParam rdf:resource="http://www.seontology.org/activeseo/seoanno/data/main/Parameter_1"/>

    <SEO:hasStaticModifier>true</SEO:hasStaticModifier>

    <SEO:hasAccessModifier rdf:resource="http://www.seontology.org/activeseo/seo/v1#Public"/>

    <foaf:name>main</foaf:name>

    <SEO:methodDeclarationSignature>void main(java.lang.String[] args)</SEO:methodDeclarationSignature>

    <rdf:type rdf:resource="http://purl.org/dc/dcmitype/Software"/>

    <SEO:returnType>void</SEO:returnType>

    <SEO:methodName>main</SEO:methodName>

    <SEO:isReturnPrimitive>true</SEO:isReturnPrimitive>

    <SEO:methodCallSignature>main(args)</SEO:methodCallSignature>

  </SEO:METHOD>

  <DC:Software rdf:about="http://www.seontology.org/activeseo/seoanno/data/solution">

    <SEO:hasMethod rdf:resource="http://www.seontology.org/activeseo/seoanno/data/main"/>

    <SEO:hasAccessModifier rdf:resource="http://www.seontology.org/activeseo/seo/v1#Public"/>

    <foaf:name>solution</foaf:name>

    <rdf:type rdf:resource="http://www.seontology.org/activeseo/seo/v1#CLASS"/>

  </DC:Software>

</rdf:RDF>

 

Annotation in graph format

 

 

 

bottom of page