edu.brandeis.cs.steele.wn
Class FileManager
java.lang.Object
|
+--edu.brandeis.cs.steele.wn.FileManager
- All Implemented Interfaces:
- FileManagerInterface, java.rmi.Remote
- Direct Known Subclasses:
- RemoteFileManager
- public class FileManager
- extends java.lang.Object
- implements FileManagerInterface
An implementation of FileManagerInterface that reads files from the local file system.
a file. FileManager
caches the file position before and after
readLineAt
in order to eliminate the redundant IO activity that a naive implementation
of these methods would necessitate.
Instances of this class are guarded. Operations are synchronized by file.
Constructor Summary |
FileManager()
Construct a file manager backed by a set of files contained in the default WN search directory. |
FileManager(java.lang.String searchDirectory)
Construct a file manager backed by a set of files contained in searchDirectory. |
Method Summary |
protected int |
compare(java.lang.String a,
java.lang.String b)
Return a negative value if a precedes b, a positive value if a follows b,
otherwise 0. |
protected java.io.RandomAccessFile |
getFileStream(java.lang.String filename)
|
long |
getIndexedLinePointer(java.lang.String filename,
java.lang.String target)
Search for the line whose first word is index (that is, that begins with
index followed by a space or tab). |
long |
getMatchingLinePointer(java.lang.String filename,
long offset,
java.lang.String substring)
Search for a line whose index word contains substring. |
long |
getNextLinePointer(java.lang.String filename,
long offset)
Search for the line following the line that begins at offset. |
protected static java.lang.String |
getWNHome()
|
protected static java.lang.String |
getWNSearchDir()
|
protected java.lang.String |
readLine(java.io.RandomAccessFile stream)
|
java.lang.String |
readLineAt(java.lang.String filename,
long offset)
Read the line that begins at file offset offset in the file named by filename. |
protected java.lang.String |
readLineWord(java.io.RandomAccessFile stream)
|
protected void |
skipLine(java.io.RandomAccessFile stream)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
VERSION
public static java.lang.String VERSION
- The API version, used by
RemoteFileManager
for constructing a binding name.
TRACE_LOOKUP
public static final boolean TRACE_LOOKUP
- Set this to true to enable debugging messages in
getIndexedLinePointer
.
IS_MW_VM
protected static final boolean IS_MW_VM
searchDirectory
protected java.lang.String searchDirectory
filenameCache
protected java.util.Hashtable filenameCache
nextLineCache
protected FileManager.NextLineCache nextLineCache
IS_WINDOWS_OS
protected static final boolean IS_WINDOWS_OS
IS_MAC_OS
protected static final boolean IS_MAC_OS
fileSeparator
protected static final java.lang.String fileSeparator
FileManager
public FileManager()
- Construct a file manager backed by a set of files contained in the default WN search directory.
The default search directory is the location named by the system property WNSEARCHDIR; or, if this
is undefined, by the directory named WNHOME/Database (under MacOS) or WNHOME/dict (otherwise);
or, if the WNHOME is undefined, the current directory (under MacOS), "C:\wn16" (WIndows),
or "/usr/local/wordnet1.6" (otherwise).
FileManager
public FileManager(java.lang.String searchDirectory)
- Construct a file manager backed by a set of files contained in searchDirectory.
getWNHome
protected static java.lang.String getWNHome()
getWNSearchDir
protected static java.lang.String getWNSearchDir()
getFileStream
protected java.io.RandomAccessFile getFileStream(java.lang.String filename)
throws java.io.IOException
readLine
protected java.lang.String readLine(java.io.RandomAccessFile stream)
throws java.io.IOException
skipLine
protected void skipLine(java.io.RandomAccessFile stream)
throws java.io.IOException
readLineAt
public java.lang.String readLineAt(java.lang.String filename,
long offset)
throws java.io.IOException
- Description copied from interface:
FileManagerInterface
- Read the line that begins at file offset offset in the file named by filename.
- Specified by:
readLineAt
in interface FileManagerInterface
readLineWord
protected java.lang.String readLineWord(java.io.RandomAccessFile stream)
throws java.io.IOException
getNextLinePointer
public long getNextLinePointer(java.lang.String filename,
long offset)
throws java.io.IOException
- Description copied from interface:
FileManagerInterface
- Search for the line following the line that begins at offset.
- Specified by:
getNextLinePointer
in interface FileManagerInterface
- Following copied from interface:
edu.brandeis.cs.steele.wn.FileManagerInterface
- Returns:
- The file offset of the start of the line, or
-1
if offset
is the last line in the file.
getMatchingLinePointer
public long getMatchingLinePointer(java.lang.String filename,
long offset,
java.lang.String substring)
throws java.io.IOException
- Description copied from interface:
FileManagerInterface
- Search for a line whose index word contains substring.
- Specified by:
getMatchingLinePointer
in interface FileManagerInterface
- Following copied from interface:
edu.brandeis.cs.steele.wn.FileManagerInterface
- Returns:
- The file offset of the start of the matchng line, or
-1
if
no such line exists.
getIndexedLinePointer
public long getIndexedLinePointer(java.lang.String filename,
java.lang.String target)
throws java.io.IOException
- Description copied from interface:
FileManagerInterface
- Search for the line whose first word is index (that is, that begins with
index followed by a space or tab). filename must name a file
whose lines are sorted by index word.
- Specified by:
getIndexedLinePointer
in interface FileManagerInterface
- Following copied from interface:
edu.brandeis.cs.steele.wn.FileManagerInterface
- Returns:
- The file offset of the start of the matching line, or
-1
if no such line
exists.
compare
protected int compare(java.lang.String a,
java.lang.String b)
- Return a negative value if a precedes b, a positive value if a follows b,
otherwise 0.