org.openrdf.elmo.smusher
Class Util

java.lang.Object
  extended by org.openrdf.elmo.smusher.Util

public class Util
extends Object


Field Summary
protected static Logger _logger
           
static String CONTEXT_PASSWORD_PARAMETER
           
static String CONTEXT_REPOSITORY_PARAMETER
           
static String CONTEXT_SERVER_PARAMETER
           
static String CONTEXT_USERNAME_PARAMETER
           
static String REQUEST_REPOSITORY_ATTRIBUTE
           
static String SERVLET_PASSWORD_PARAMETER
           
static String SERVLET_REPOSITORY_PARAMETER
           
static String SERVLET_SERVER_PARAMETER
           
static String SERVLET_USERNAME_PARAMETER
           
static double SIMILARITY_THRESHOLD
           
 
Constructor Summary
Util()
           
 
Method Summary
static void addStatememt(Repository rep, Statement stmt)
          Add a statement to a repository
static double compare(String str1, String str2, int ng)
           
static String createSHA1(String str)
          Generate a SHA1 digest of the string passed in and encode using hex encoding.
static Literal createSha1Sum(String email)
          Generate a SHA1 summary of an email address String (e.g.
static Literal createSha1Sum(URI email)
          Generate a SHA1 summary of an email address URI (e.g.
static
<T extends Resource>
List<T>
getAllInstances(ElmoManager manager, Class<T> cl)
          Get all instances of type T from a given repository
static String getFirstName(String name)
          Extract the first name from a full name
static String getLastName(String name)
          Extract the last name from a full name
static SesameManager initManager(Repository repository)
           
static Repository initRepository(HttpServletRequest request)
          Initialize an Elmo repository from servlet request.
static Repository initRepository(ServletConfig config)
          Initialize an Elmo repository from servlet initialization parameters and if that fails from the context initialization parameters.
static Repository initRepository(ServletConfig config, HttpServletRequest request)
          Initialize an Elmo repository from either servlet request parameters or servlet initialization parameters.
static Repository initRepository(String repositoryLocation, String repositoryName)
          Initialize a remote Elmo repository using the location and name
static Repository initRepository(String repositoryLocation, String repositoryName, String username, String password)
          Initialize a remote Elmo repository using (optional) username and password.
static String invertName(String name)
          Invert names of the from "van Harmelen, Frank", i.e.
static boolean matchNames(String name1, String name2)
          Determine if two names are the same using N-Gram matching.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIMILARITY_THRESHOLD

public static final double SIMILARITY_THRESHOLD
See Also:
Constant Field Values

SERVLET_SERVER_PARAMETER

public static final String SERVLET_SERVER_PARAMETER
See Also:
Constant Field Values

SERVLET_REPOSITORY_PARAMETER

public static final String SERVLET_REPOSITORY_PARAMETER
See Also:
Constant Field Values

SERVLET_USERNAME_PARAMETER

public static final String SERVLET_USERNAME_PARAMETER
See Also:
Constant Field Values

SERVLET_PASSWORD_PARAMETER

public static final String SERVLET_PASSWORD_PARAMETER
See Also:
Constant Field Values

CONTEXT_SERVER_PARAMETER

public static final String CONTEXT_SERVER_PARAMETER
See Also:
Constant Field Values

CONTEXT_REPOSITORY_PARAMETER

public static final String CONTEXT_REPOSITORY_PARAMETER
See Also:
Constant Field Values

CONTEXT_USERNAME_PARAMETER

public static final String CONTEXT_USERNAME_PARAMETER
See Also:
Constant Field Values

CONTEXT_PASSWORD_PARAMETER

public static final String CONTEXT_PASSWORD_PARAMETER
See Also:
Constant Field Values

REQUEST_REPOSITORY_ATTRIBUTE

public static final String REQUEST_REPOSITORY_ATTRIBUTE
See Also:
Constant Field Values

_logger

protected static Logger _logger
Constructor Detail

Util

public Util()
Method Detail

initManager

public static SesameManager initManager(Repository repository)

initRepository

public static Repository initRepository(String repositoryLocation,
                                        String repositoryName)
                                 throws Exception
Initialize a remote Elmo repository using the location and name

Parameters:
repositoryLocation - String containing a URL
repositoryName - Repository name
Returns:
Repository
Throws:
Exception - if parameter is missing, invalid or initilization failed
See Also:
elmo.repository.ElmoRepository

initRepository

public static Repository initRepository(String repositoryLocation,
                                        String repositoryName,
                                        String username,
                                        String password)
                                 throws Exception
Initialize a remote Elmo repository using (optional) username and password. Performs some sanity checks on the repository location and name.

Parameters:
repositoryLocation - URL of the server
repositoryName - Repository name
username - Optional username
password - Optional password
Returns:
Repository
Throws:
Exception - if parameter is missing, invalid or initilization failed

initRepository

public static Repository initRepository(HttpServletRequest request)
                                 throws ServletException
Initialize an Elmo repository from servlet request. First try to find a SesameRepository as a request attribute , if fails try to initialize one using request parameter. The attribute and init parameter names to specified are defined as constants in this class.

Parameters:
request - Request with parameters
Returns:
Repository
Throws:
ServletException - if parameters are missing or repository failed to initialize
See Also:
REQUEST_REPOSITORY_ATTRIBUTE, SERVLET_SERVER_PARAMETER, SERVLET_REPOSITORY_PARAMETER, SERVLET_USERNAME_PARAMETER, SERVLET_USERNAME_PARAMETER

initRepository

public static Repository initRepository(ServletConfig config)
                                 throws ServletException
Initialize an Elmo repository from servlet initialization parameters and if that fails from the context initialization parameters. The init parameter names to specified are defined as constants in this class.

Parameters:
config - ServletConfig instance
Returns:
Repository
Throws:
ServletException - if parameters are missing or repository failed to initialize
See Also:
SERVLET_SERVER_PARAMETER, SERVLET_REPOSITORY_PARAMETER, SERVLET_USERNAME_PARAMETER, SERVLET_PASSWORD_PARAMETER, CONTEXT_SERVER_PARAMETER, CONTEXT_REPOSITORY_PARAMETER, CONTEXT_USERNAME_PARAMETER, CONTEXT_PASSWORD_PARAMETER

initRepository

public static Repository initRepository(ServletConfig config,
                                        HttpServletRequest request)
                                 throws ServletException
Initialize an Elmo repository from either servlet request parameters or servlet initialization parameters. First try to find a ElmoRepository object in the request. If not present, try to initialize one based on request parameters. If this also fails, try to use servlet init parameters and lastly the context initialization paratemers. The attribute, request and init parameter names to specified are defined as constants in this class.

Parameters:
servlet - Servlet instance
request - Request with parameters
Returns:
Repository
Throws:
ServletException - if parameters are missing or repository failed to initialize
See Also:
REQUEST_REPOSITORY_ATTRIBUTE, SERVLET_SERVER_PARAMETER, SERVLET_REPOSITORY_PARAMETER, SERVLET_USERNAME_PARAMETER, SERVLET_USERNAME_PARAMETER, CONTEXT_SERVER_PARAMETER, CONTEXT_REPOSITORY_PARAMETER, CONTEXT_USERNAME_PARAMETER, CONTEXT_USERNAME_PARAMETER

compare

public static double compare(String str1,
                             String str2,
                             int ng)

invertName

public static String invertName(String name)
Invert names of the from "van Harmelen, Frank", i.e. with comma.

Parameters:
name - Name
Returns:
Name in its regular form or unchanged if no comma is found

getFirstName

public static String getFirstName(String name)
Extract the first name from a full name

Parameters:
name - Name
Returns:
First name

getLastName

public static String getLastName(String name)
Extract the last name from a full name

Parameters:
name - Name
Returns:
Last name

matchNames

public static boolean matchNames(String name1,
                                 String name2)
Determine if two names are the same using N-Gram matching. The similarity threshold is determined by SIMILARITY_THRESHOLD

Parameters:
name1 - First name
name2 - Second name
Returns:
True, if the names are the same (similar enough)

addStatememt

public static void addStatememt(Repository rep,
                                Statement stmt)
                         throws OpenRDFException,
                                IOException
Add a statement to a repository

Parameters:
rep -
stmt -
Throws:
OpenRDFException
IOException

getAllInstances

public static <T extends Resource> List<T> getAllInstances(ElmoManager manager,
                                                           Class<T> cl)
Get all instances of type T from a given repository

Type Parameters:
T -
Parameters:
rep -
cl -
Returns:

createSHA1

public static final String createSHA1(String str)
                               throws UnsupportedEncodingException,
                                      NoSuchAlgorithmException
Generate a SHA1 digest of the string passed in and encode using hex encoding.

Parameters:
str - String to be encoded
Returns:
Digest
Throws:
UnsupportedEncodingException
NoSuchAlgorithmException

createSha1Sum

public static final Literal createSha1Sum(String email)
                                   throws UnsupportedEncodingException,
                                          NoSuchAlgorithmException
Generate a SHA1 summary of an email address String (e.g. "pmika@cs.vu.nl") according the FOAF specification of the mbox_sha1sum property.

Parameters:
str - E-mail address
Returns:
Mailbox checksum
Throws:
UnsupportedEncodingException
NoSuchAlgorithmException

createSha1Sum

public static final Literal createSha1Sum(URI email)
                                   throws UnsupportedEncodingException,
                                          NoSuchAlgorithmException
Generate a SHA1 summary of an email address URI (e.g. ) according the FOAF specification of the mbox_sha1sum property.

Parameters:
str -
Returns:
Mailbox checksum
Throws:
UnsupportedEncodingException
NoSuchAlgorithmException


Copyright © 2004-2008 Aduna. All Rights Reserved.