You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by ko...@apache.org on 2012/12/20 07:34:51 UTC

svn commit: r1424339 - in /labs/alike/trunk: ./ demo/ src/java/org/apache/alike/ src/test/org/apache/alike/ src/test/test-files/

Author: koji
Date: Thu Dec 20 06:34:51 2012
New Revision: 1424339

URL: http://svn.apache.org/viewvc?rev=1424339&view=rev
Log:
add AlikeConfig to read and parse xml config file

Added:
    labs/alike/trunk/src/java/org/apache/alike/AlikeConfig.java
    labs/alike/trunk/src/test/org/apache/alike/AlikeConfigTest.java
    labs/alike/trunk/src/test/test-files/
    labs/alike/trunk/src/test/test-files/valid-conf.xml
Modified:
    labs/alike/trunk/build.xml
    labs/alike/trunk/demo/   (props changed)
    labs/alike/trunk/demo/build.xml
    labs/alike/trunk/demo/demo-conf.xml
    labs/alike/trunk/src/java/org/apache/alike/PrepareInputVectors.java

Modified: labs/alike/trunk/build.xml
URL: http://svn.apache.org/viewvc/labs/alike/trunk/build.xml?rev=1424339&r1=1424338&r2=1424339&view=diff
==============================================================================
--- labs/alike/trunk/build.xml (original)
+++ labs/alike/trunk/build.xml Thu Dec 20 06:34:51 2012
@@ -96,7 +96,7 @@
                haltonfailure="no"
                errorProperty="tests.failed"
                failureProperty="tests.failed"
-               dir="${src.dir}/test">
+               dir="${src.dir}/test/test-files">
             <classpath refid="common.path.lib"/>
             <classpath path="${cls.dir}"/>
             <classpath path="${test.cls.dir}"/>

Propchange: labs/alike/trunk/demo/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Dec 20 06:34:51 2012
@@ -7,3 +7,4 @@ init-clusters
 output-clusters
 result-centroids.txt
 solr-demo-data.xml
+.input-vectors.crc

Modified: labs/alike/trunk/demo/build.xml
URL: http://svn.apache.org/viewvc/labs/alike/trunk/demo/build.xml?rev=1424339&r1=1424338&r2=1424339&view=diff
==============================================================================
--- labs/alike/trunk/demo/build.xml (original)
+++ labs/alike/trunk/demo/build.xml Thu Dec 20 06:34:51 2012
@@ -23,9 +23,9 @@
     <import file="../build.xml"/>
 
     <target name="piv" depends="alike-compile" description="run PrepareInputVectors">
-        <java classname="org.apache.alike.PrepareInputVectors" fork="true">
+        <java classname="org.apache.alike.PrepareInputVectors" dir="demo" fork="true">
             <jvmarg line="-Dfile.encoding=UTF-8"/>
-            <arg line="demo/desc demo/input-vectors/data"/>
+            <arg line="demo-conf.xml"/>
             <classpath refid="common.path.lib"/>
             <classpath path="${cls.dir}"/>
         </java>
@@ -48,7 +48,7 @@
         <delete dir="demo/solrhome/collection1/data"/>
         <delete includeemptydirs="true">
             <fileset dir="demo/desc" includes="**/*"/>
-            <fileset dir="demo" includes="result-centroids.txt"/>
+            <fileset dir="demo" includes="result-centroids.txt,.input-vectors.crc"/>
         </delete>
     </target>
 

Modified: labs/alike/trunk/demo/demo-conf.xml
URL: http://svn.apache.org/viewvc/labs/alike/trunk/demo/demo-conf.xml?rev=1424339&r1=1424338&r2=1424339&view=diff
==============================================================================
--- labs/alike/trunk/demo/demo-conf.xml (original)
+++ labs/alike/trunk/demo/demo-conf.xml Thu Dec 20 06:34:51 2012
@@ -20,7 +20,7 @@
 
   <visualDescriptorsExtraction>
     <!-- method should be one of sift, surf or orb -->
-    <method>orb</method>
+    <method>surf</method>
     <descDir>
       <normalfs>desc</normalfs>
       <hdfs>input-vectors</hdfs>
@@ -32,7 +32,7 @@
     <cluster method="kmeans">
       <param name="maxIter">10</param>
       <param name="cd">0.01</param>
-      <param name="init">init-clusters</param>
+      <param name="init">demo/init-clusters</param>
     </cluster>
     <dump file="result-centroids.txt"/>
   </clustering>
@@ -45,7 +45,7 @@
     </fieldNames>
     <indexer class="org.apache.alike.SolrStandardXMLIndexer">
       <histogramMatcher class="LeastSquaresHistogramMatcher"/>
-      <param name="file">solr-demo-data.xml</param>
+      <param name="file">demo/solr-demo-data.xml</param>
     </indexer>
   </vectorQuantization>
 

Added: labs/alike/trunk/src/java/org/apache/alike/AlikeConfig.java
URL: http://svn.apache.org/viewvc/labs/alike/trunk/src/java/org/apache/alike/AlikeConfig.java?rev=1424339&view=auto
==============================================================================
--- labs/alike/trunk/src/java/org/apache/alike/AlikeConfig.java (added)
+++ labs/alike/trunk/src/java/org/apache/alike/AlikeConfig.java Thu Dec 20 06:34:51 2012
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.alike;
+
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.xml.sax.InputSource;
+
+public final class AlikeConfig {
+
+  private final XPath xpath;
+  private final InputSource is;
+  
+  public AlikeConfig(String confFile){
+    is = new InputSource(confFile);
+    xpath = XPathFactory.newInstance().newXPath();
+  }
+  
+  public String getMethod(){
+    return getStringValue("/config/visualDescriptorsExtraction/method/text()");
+  }
+  
+  public String getDescNormalFSDir(){
+    return getStringValue("/config/visualDescriptorsExtraction/descDir/normalfs/text()");
+  }
+  
+  public String getDescHDFSDir(){
+    return getStringValue("/config/visualDescriptorsExtraction/descDir/hdfs/text()");
+  }
+  
+  private String getStringValue(String exp){
+    try {
+      return ((String)xpath.evaluate(exp, is, XPathConstants.STRING)).trim();
+    } catch (XPathExpressionException e) {
+      throw new RuntimeException(e);
+    }
+  }
+}

Modified: labs/alike/trunk/src/java/org/apache/alike/PrepareInputVectors.java
URL: http://svn.apache.org/viewvc/labs/alike/trunk/src/java/org/apache/alike/PrepareInputVectors.java?rev=1424339&r1=1424338&r2=1424339&view=diff
==============================================================================
--- labs/alike/trunk/src/java/org/apache/alike/PrepareInputVectors.java (original)
+++ labs/alike/trunk/src/java/org/apache/alike/PrepareInputVectors.java Thu Dec 20 06:34:51 2012
@@ -44,28 +44,31 @@ import org.apache.mahout.math.VectorWrit
 public class PrepareInputVectors {
 
   /**
-   * The main program that takes two arguments.
+   * The main program that takes the path to alikeconfig.xml.
    * 
-   * @param args the first argument is the parent directory of visual descriptors.
-   *             the second argument is output file path.
+   * @param args file path to alikeconfig.xml
    * @throws IOException 
+   * 
+   * @see {@link AlikeConfig}
    */
   public static void main(String[] args) throws IOException {
-    if(args.length != 2){
+    if(args.length != 1){
       printUsage(1);
     }
     
-    VisualDescriptors2MahoutExecutor executor = new VisualDescriptors2MahoutExecutor(args[1]);
-    FileUtil.executeRecursively(executor, args[0]);
+    AlikeConfig config = new AlikeConfig(args[0]);
+    
+    VisualDescriptors2MahoutExecutor executor =
+        new VisualDescriptors2MahoutExecutor(config.getDescHDFSDir());
+    FileUtil.executeRecursively(executor, config.getDescNormalFSDir());
     executor.closeWriter();
     
   }
 
   static void printUsage(int exit){
-    System.err.printf("Usage: $ java %s <parent_dir_path> <output_file_path>\n",
+    System.err.printf("Usage: $ java %s <path-to-alikeconfig.xml>\n",
         PrepareInputVectors.class.getName());
-    System.err.println("\t<parent_dir_path> parent directory path of visual descriptors");
-    System.err.println("\t<output_file_path> output file path for Mahout");
+    System.err.println("\t<path-to-alikeconfig.xml> the file path to alikeconfig.xml");
 
     if(exit >= 0){
       System.exit(exit);

Added: labs/alike/trunk/src/test/org/apache/alike/AlikeConfigTest.java
URL: http://svn.apache.org/viewvc/labs/alike/trunk/src/test/org/apache/alike/AlikeConfigTest.java?rev=1424339&view=auto
==============================================================================
--- labs/alike/trunk/src/test/org/apache/alike/AlikeConfigTest.java (added)
+++ labs/alike/trunk/src/test/org/apache/alike/AlikeConfigTest.java Thu Dec 20 06:34:51 2012
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.alike;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class AlikeConfigTest {
+
+  @Test(expected=RuntimeException.class)
+  public void testNoConfFile() throws Exception {
+    new AlikeConfig("not-exist.xml").getMethod();
+  }
+  
+  private static AlikeConfig config;
+  
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    config = new AlikeConfig("valid-conf.xml");
+  }
+  
+  @Test
+  public void testGetMethod() throws Exception {
+    assertEquals("orb", config.getMethod());
+  }
+  
+  @Test
+  public void testGetDescNormalFSDir() throws Exception {
+    assertEquals("desc", config.getDescNormalFSDir());
+  }
+  
+  @Test
+  public void testGetDescHDFSDir() throws Exception {
+    assertEquals("input-vectors", config.getDescHDFSDir());
+  }
+}

Added: labs/alike/trunk/src/test/test-files/valid-conf.xml
URL: http://svn.apache.org/viewvc/labs/alike/trunk/src/test/test-files/valid-conf.xml?rev=1424339&view=auto
==============================================================================
--- labs/alike/trunk/src/test/test-files/valid-conf.xml (added)
+++ labs/alike/trunk/src/test/test-files/valid-conf.xml Thu Dec 20 06:34:51 2012
@@ -0,0 +1,52 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+<config>
+
+  <visualDescriptorsExtraction>
+    <!-- method should be one of sift, surf or orb -->
+    <method>orb</method>
+    <descDir>
+      <normalfs>desc</normalfs>
+      <hdfs>input-vectors</hdfs>
+    </descDir>
+  </visualDescriptorsExtraction>
+
+  <clustering k="1000">
+    <outDir>output-clusters</outDir>
+    <cluster method="kmeans">
+      <param name="maxIter">10</param>
+      <param name="cd">0.01</param>
+      <param name="init">init-clusters</param>
+    </cluster>
+    <dump file="result-centroids.txt"/>
+  </clustering>
+
+  <vectorQuantization>
+    <fieldNames>
+      <imageFileFieldName>imgFile</imageFileFieldName>
+      <queryFieldName>query</queryFieldName>
+      <histogramFieldName>histogram</histogramFieldName>
+    </fieldNames>
+    <indexer class="org.apache.alike.SolrStandardXMLIndexer">
+      <histogramMatcher class="LeastSquaresHistogramMatcher"/>
+      <param name="file">solr-demo-data.xml</param>
+    </indexer>
+  </vectorQuantization>
+
+</config>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org