From: <ki...@us...> - 2014-02-25 12:08:26
|
Revision: 4242 http://sourceforge.net/p/dl-learner/code/4242 Author: kirdie Date: 2014-02-25 12:08:21 +0000 (Tue, 25 Feb 2014) Log Message: ----------- added quoting in index and others stuff i forgot. Modified Paths: -------------- trunk/components-core/pom.xml trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-ext/pom.xml trunk/components-ext/src/main/java/org/dllearner/common/index/Index.java trunk/components-ext/src/main/java/org/dllearner/common/index/MappingBasedIndex.java Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2014-02-25 12:01:14 UTC (rev 4241) +++ trunk/components-core/pom.xml 2014-02-25 12:08:21 UTC (rev 4242) @@ -20,6 +20,7 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> + <version>2.4.3</version> <configuration> <!-- Uncomment this when the junits are independent of a runtime directory --> <!--<includes> --> @@ -58,7 +59,7 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> - <version>2.8</version> + <version>2.9</version> <configuration> <show>public</show> <nohelp>true</nohelp> Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2014-02-25 12:01:14 UTC (rev 4241) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2014-02-25 12:08:21 UTC (rev 4242) @@ -563,12 +563,10 @@ if(values == null){ try { values = (T) value.getClass().newInstance(); - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); + values.add(value); } - values.add(value); + catch (InstantiationException e) {e.printStackTrace();return;} + catch (IllegalAccessException e) {e.printStackTrace();return;} } values.add(value); } Modified: trunk/components-ext/pom.xml =================================================================== --- trunk/components-ext/pom.xml 2014-02-25 12:01:14 UTC (rev 4241) +++ trunk/components-ext/pom.xml 2014-02-25 12:08:21 UTC (rev 4242) @@ -133,6 +133,36 @@ </dependencies> <build> <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>2.9</version> + <configuration> + <show>public</show> + <nohelp>true</nohelp> + <destDir>doc/javadoc</destDir> + <doctitle>DL-Learner Javadoc</doctitle> + <author>true</author> + <nodeprecated>false</nodeprecated> + <nodeprecatedlist>false</nodeprecatedlist> + <noindex>false</noindex> + <nonavbar>false</nonavbar> + <notree>false</notree> + <overview>src/etc/overview.html</overview> + <source>1.6</source> + <sourcepath>src/main/java</sourcepath> + <splitindex>true</splitindex> + <stylesheetfile>src/etc/javadoc.css</stylesheetfile> + <use>true</use> + <version>true</version> + <linksource>true</linksource> + <bottom><img style='float:right' src='http://sflogo.sourceforge.net/sflogo.php?group_id=203619&type=1' width='88' height='31' border='0' alt='SourceForge.net Logo' /> DL-Learner is licenced under the terms of the GNU General Public License.<br />Copyright &#169; 2007-2011 Jens Lehmann</bottom> + <encoding>ISO-8859-1</encoding> + <windowtitle>DL-Learner Javadoc</windowtitle> + </configuration> + </plugin> + <!-- <plugin> <groupId>org.codehaus.mojo</groupId> @@ -151,6 +181,7 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> + <version>2.4.3</version> <configuration> <excludes> <exclude>org/dllearner/algorithm/tbsl/*</exclude> @@ -161,7 +192,7 @@ <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> - <version>1.2</version> + <version>1.2.1</version> <executions> <execution> Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/Index.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/Index.java 2014-02-25 12:01:14 UTC (rev 4241) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/Index.java 2014-02-25 12:08:21 UTC (rev 4242) @@ -5,9 +5,11 @@ public abstract class Index { static final int DEFAULT_LIMIT = 10; - + + String enquote(String s) {if(!s.startsWith("(")) s='('+s+')'; return s;} + public List<String> getResources(String queryString) {return getResources(queryString,DEFAULT_LIMIT);} - public List<String> getResources(String queryString, int limit) {return getResources(queryString,DEFAULT_LIMIT,0);} + public List<String> getResources(String queryString, int limit) {return getResources(enquote(queryString),DEFAULT_LIMIT,0);} abstract public List<String> getResources(String queryString, int limit, int offset); public IndexResultSet getResourcesWithScores(String queryString) {return getResourcesWithScores(queryString,DEFAULT_LIMIT);} Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/MappingBasedIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/MappingBasedIndex.java 2014-02-25 12:01:14 UTC (rev 4241) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/MappingBasedIndex.java 2014-02-25 12:08:21 UTC (rev 4242) @@ -5,6 +5,8 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -12,101 +14,43 @@ import java.util.Map.Entry; public class MappingBasedIndex { - - private Map<String, List<String>> classUri2TokensMap = new HashMap<String, List<String>>(); - private Map<String, List<String>> resourceUri2TokensMap = new HashMap<String, List<String>>(); - private Map<String, List<String>> datatypePropertyUri2TokensMap = new HashMap<String, List<String>>(); - private Map<String, List<String>> objectPropertyUri2TokensMap = new HashMap<String, List<String>>(); - - public MappingBasedIndex(String classMappingsFile, String resourceMappingsFile, - String dataPropertyMappingsFile, String objectPropertyMappingsFile) { - BufferedReader br = null; - String line = null; - try { - //load class mappings - if(classMappingsFile != null){ - br = new BufferedReader(new FileReader(new File(classMappingsFile))); - while((line = br.readLine()) != null){ - int split = line.indexOf("|"); - //get the URI - String uri = line.substring(0, split); - //get the list of tokens - List<String> tokens = new ArrayList<String>(); - String tokenString = line.substring(split + 1); - String[] tokenArray = tokenString.split(","); - for(String token : tokenArray){ - tokens.add(token.trim()); - } - - classUri2TokensMap.put(uri, tokens); - } + + private final Map<String, List<String>> classUri2TokensMap; + private final Map<String, List<String>> resourceUri2TokensMap; + private final Map<String, List<String>> datatypePropertyUri2TokensMap; + private final Map<String, List<String>> objectPropertyUri2TokensMap; + + Map<String,List<String>> uriToTokens(InputStream mapping) throws IOException + { + Map<String, List<String>> uriToTokens = new HashMap<>(); + try(BufferedReader in = new BufferedReader(new InputStreamReader(mapping))) + { + String line = null; + while((line = in.readLine()) != null) + { + int split = line.indexOf("|"); + //get the URI + String uri = line.substring(0, split); + //get the list of tokens + List<String> tokens = new ArrayList<String>(); + String tokenString = line.substring(split + 1); + String[] tokenArray = tokenString.split(","); + for(String token : tokenArray){tokens.add(token.trim());} + uriToTokens.put(uri, tokens); } - - //load resource mappings - if(resourceMappingsFile != null){ - br = new BufferedReader(new FileReader(new File(resourceMappingsFile))); - while((line = br.readLine()) != null){ - int split = line.indexOf("|"); - //get the URI - String uri = line.substring(0, split); - //get the list of tokens - List<String> tokens = new ArrayList<String>(); - String tokenString = line.substring(split + 1); - String[] tokenArray = tokenString.split(","); - for(String token : tokenArray){ - tokens.add(token.trim()); - } - - resourceUri2TokensMap.put(uri, tokens); - } - } - - //load object property mappings - if(objectPropertyMappingsFile != null){ - br = new BufferedReader(new FileReader(new File(objectPropertyMappingsFile))); - while((line = br.readLine()) != null){ - int split = line.indexOf("|"); - //get the URI - String uri = line.substring(0, split); - //get the list of tokens - List<String> tokens = new ArrayList<String>(); - String tokenString = line.substring(split + 1); - String[] tokenArray = tokenString.split(","); - for(String token : tokenArray){ - tokens.add(token.trim()); - } - - objectPropertyUri2TokensMap.put(uri, tokens); - } - } - - //load datatype property mappings - if(dataPropertyMappingsFile != null){ - br = new BufferedReader(new FileReader(new File(dataPropertyMappingsFile))); - while((line = br.readLine()) != null){ - int split = line.indexOf("|"); - //get the URI - String uri = line.substring(0, split); - //get the list of tokens - List<String> tokens = new ArrayList<String>(); - String tokenString = line.substring(split + 1); - String[] tokenArray = tokenString.split(","); - for(String token : tokenArray){ - tokens.add(token.trim()); - } - - datatypePropertyUri2TokensMap.put(uri, tokens); - } - } - - - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } + return uriToTokens; + } } - + + public MappingBasedIndex(InputStream classMappingsFile, InputStream resourceMappingsFile, + InputStream dataPropertyMappingsFile, InputStream objectPropertyMappingsFile) throws IOException + { + classUri2TokensMap=uriToTokens(classMappingsFile); + resourceUri2TokensMap=uriToTokens(resourceMappingsFile); + datatypePropertyUri2TokensMap=uriToTokens(dataPropertyMappingsFile); + objectPropertyUri2TokensMap=uriToTokens(objectPropertyMappingsFile); + } + public List<String> getClasses(String token){ List<String> uris = new ArrayList<String>(); for(Entry<String, List<String>> entry : classUri2TokensMap.entrySet()){ @@ -116,8 +60,8 @@ } return uris; } - - public List<String> getResources(String token){ + + public List<String> getResourceAsStreams(String token){ List<String> uris = new ArrayList<String>(); for(Entry<String, List<String>> entry : resourceUri2TokensMap.entrySet()){ if(entry.getValue().contains(token)){ @@ -126,7 +70,7 @@ } return uris; } - + public List<String> getObjectProperties(String token){ List<String> uris = new ArrayList<String>(); for(Entry<String, List<String>> entry : objectPropertyUri2TokensMap.entrySet()){ @@ -136,7 +80,7 @@ } return uris; } - + public List<String> getDatatypeProperties(String token){ List<String> uris = new ArrayList<String>(); for(Entry<String, List<String>> entry : datatypePropertyUri2TokensMap.entrySet()){ @@ -146,14 +90,14 @@ } return uris; } - + public List<String> getProperties(String token){ List<String> uris = new ArrayList<String>(); uris.addAll(getObjectProperties(token)); uris.addAll(getDatatypeProperties(token)); return uris; } - + public IndexResultSet getClassesWithScores(String token){ IndexResultSet rs = new IndexResultSet(); for(String uri : getClasses(token)){ @@ -161,15 +105,15 @@ } return rs; } - - public IndexResultSet getResourcesWithScores(String token){ + + public IndexResultSet getResourceAsStreamsWithScores(String token){ IndexResultSet rs = new IndexResultSet(); - for(String uri : getResources(token)){ + for(String uri : getResourceAsStreams(token)){ rs.addItem(new IndexResultItem(uri, token, 1f)); } return rs; } - + public IndexResultSet getObjectPropertiesWithScores(String token){ IndexResultSet rs = new IndexResultSet(); for(String uri : getObjectProperties(token)){ @@ -177,7 +121,7 @@ } return rs; } - + public IndexResultSet getDatatypePropertiesWithScores(String token){ IndexResultSet rs = new IndexResultSet(); for(String uri : getDatatypeProperties(token)){ @@ -185,7 +129,7 @@ } return rs; } - + public IndexResultSet getPropertiesWithScores(String token){ IndexResultSet rs = new IndexResultSet(); for(String uri : getProperties(token)){ @@ -193,7 +137,7 @@ } return rs; } - + public Boolean isDataProperty(String uri){ if(datatypePropertyUri2TokensMap.containsKey(uri)) { return true; @@ -202,9 +146,9 @@ } return null; } - - public static void main(String[] args) { - MappingBasedIndex index = new MappingBasedIndex(MappingBasedIndex.class.getClassLoader().getResource("tbsl/oxford_class_mappings.txt").getPath(), null, null, null); + + public static void main(String[] args) throws IOException { + MappingBasedIndex index = new MappingBasedIndex(MappingBasedIndex.class.getClassLoader().getResourceAsStream("tbsl/oxford_class_mappings.txt"),null, null, null); System.out.println(index.getClasses("flat")); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |