Skip to content

Commit

Permalink
#10 - Using WordNet as Maven Dependency
Browse files Browse the repository at this point in the history
- Fixed default resource file
- Added possibility to set custom workspace via a system property, very useful in unit tests
  • Loading branch information
reckart committed Apr 7, 2018
1 parent af85460 commit 198548b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright 2018
* Ubiquitous Knowledge Processing (UKP) Lab
* Technische Universität Darmstadt
*
* Licensed 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 de.tudarmstadt.ukp.dkpro.lexsemresource;

import java.io.File;

public class LSRFramework
{
public static final String ENV_DKPRO_HOME = "DKPRO_HOME";
public static final String SYS_LSR_WORKSPACE = "dkpro.lsr.workspace";

private static File workspace;

public static void setWorkspace(File aWorkspace)
{
workspace = aWorkspace;
}

/**
* Get the workspace directory.
*
* @return the workspace directory.
*/
public static File getWorkspace()
{
if (workspace != null) {
return workspace;
}

if (System.getProperty(SYS_LSR_WORKSPACE) != null) {
return new File(System.getProperty(SYS_LSR_WORKSPACE));
}

if (System.getenv(ENV_DKPRO_HOME) != null) {
return new File(System.getenv(ENV_DKPRO_HOME));
}

throw new IllegalStateException(
"Environment variable or system property [" + ENV_DKPRO_HOME + "] not set");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.springframework.context.support.FileSystemXmlApplicationContext;

import de.tudarmstadt.ukp.dkpro.lexsemresource.LSRFramework;
import de.tudarmstadt.ukp.dkpro.lexsemresource.LexicalSemanticResource;
import de.tudarmstadt.ukp.dkpro.lexsemresource.exception.ResourceLoaderException;

Expand All @@ -38,7 +39,6 @@
*/
public class ResourceFactory
{
public static final String ENV_DKPRO_HOME = "DKPRO_HOME";
public final static String CONFIG_FILE = "resources.xml";
public final static String DEFAULT_CONFIG_FILE = "/de/tudarmstadt/ukp/dkpro/lexsemresource/core/default-resources.xml";

Expand Down Expand Up @@ -152,15 +152,8 @@ public Collection<LexicalSemanticResource> getAll()
* @return the workspace directory.
* @throws IOException if the workspace cannot be obtained
*/
private static
File getWorkspace()
throws IOException
private static File getWorkspace() throws IOException
{
if (System.getenv(ENV_DKPRO_HOME) != null) {
File f = new File(System.getenv(ENV_DKPRO_HOME));
return new File(f, ResourceFactory.class.getName());
}

throw new IOException("Environment variable ["+ENV_DKPRO_HOME+"] not set");
return new File(LSRFramework.getWorkspace(), ResourceFactory.class.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<bean id="wordnet-en" lazy-init="true"
class="de.tudarmstadt.ukp.lexsemresource.resource.WordNetResource">
<bean id="wordnet-default-en" lazy-init="true"
class="de.tudarmstadt.ukp.dkpro.lexsemresource.wordnet.WordNetResource">
</bean>
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
import org.jgrapht.graph.DefaultEdge;

import de.tudarmstadt.ukp.dkpro.lexsemresource.Entity;
import de.tudarmstadt.ukp.dkpro.lexsemresource.LSRFramework;
import de.tudarmstadt.ukp.dkpro.lexsemresource.LexicalSemanticResource;
import de.tudarmstadt.ukp.dkpro.lexsemresource.core.ResourceFactory;
import de.tudarmstadt.ukp.dkpro.lexsemresource.core.util.LoggingUtils;
import de.tudarmstadt.ukp.dkpro.lexsemresource.core.util.ProgressMeter;
import de.tudarmstadt.ukp.dkpro.lexsemresource.exception.LexicalSemanticResourceException;
Expand Down Expand Up @@ -108,13 +108,7 @@ public EntityGraphJGraphT(File aGraphDirectory)
graphDirectory = aGraphDirectory;
}
else {
if (System.getenv(ResourceFactory.ENV_DKPRO_HOME) == null) {
throw new IllegalStateException(
"Environment variable [" + ResourceFactory.ENV_DKPRO_HOME + "] not set");
}

graphDirectory = new File(System.getenv(ResourceFactory.ENV_DKPRO_HOME)
+ "/" + EntityGraphJGraphT.class.getName());
graphDirectory = getWorkspace();
}

if (!graphDirectory.exists()) {
Expand Down Expand Up @@ -1619,4 +1613,14 @@ public boolean isHyponymCountMapUseLcc()
{
return hyponymCountMapUseLcc;
}

/**
* Get the workspace directory.
*
* @return the workspace directory.
*/
private static File getWorkspace()
{
return new File(LSRFramework.getWorkspace(), EntityGraphJGraphT.class.getName());
}
}

0 comments on commit 198548b

Please sign in to comment.