public class Library
extends java.lang.Object
Context
s that are active. Each language
or culture has its own Context. The Library class maintains a directory of all known
Contexts; it reads them into memory and writes them out as needed. Contexts
are stored & accessed by language-name.
When a SILK file is loaded (its context is called the Context Under Construction), all the editor variables and other options that are not specific to the context are stored in the Library.
There is only one Library. All methods and fields are static.
Modifier and Type | Class and Description |
---|---|
static class |
Library.BaseCB_Ptr
This class implements a BaseCB pointer (to be stored in CB_EQCs in the BaseClauseIndex).
|
static class |
Library.CB_EQC |
static class |
Library.CB_Ptr
This class implements a ClauseBody pointer (to be stored in CB_EQCs in the ClauseIndex).
|
static class |
Library.ClauseCounts
The Library's
ClauseCounts class is a TreeMap with structure:
LangName:kinTerm => Counter[] (cumulative counts of string length). |
static class |
Library.ClauseIndex
The Library's
ClauseIndex class contains a TreeMap with key = Exact_PC-String
and value = ArrayList |
static class |
Library.KTD_Coder
The Library's
KTD_Coder class holds a numeric code (serial number) for this KTD in the
language, plus the exactSignature for this KTD. |
static class |
Library.KTD_EQC
The Library's
KTD_EQC class defines equivalence classes for
KinTermDef s. |
static class |
Library.KTD_Ptr
This class implements a KinTermDef pointer (to be stored in KTD_EQCs in
the ClauseIndex).
|
Modifier and Type | Field and Description |
---|---|
static java.util.TreeMap |
activeContexts
The list of all activeContexts, indexed by language name.
|
static int |
changeCounter |
static Context |
contextUnderConstruction
The name of the current User's target culture.
|
static java.lang.String |
currDataAuthor |
static java.lang.String |
currentLanguage
The language name most recently chosen in the Languages Menu.
|
static java.lang.String |
editDirectory
The default directory for the current User's SILK files.
|
static java.lang.String |
helpDirectory |
static java.util.ArrayList<java.lang.String> |
langCodes |
static java.lang.String |
libraryCtxtDirectory
The default directory (or folder) holding Contexts.
|
static java.lang.String |
libraryDirectory
The default directory (or folder) holding this Library's material.
|
static MyResBundle |
menuItems |
static java.lang.String |
menuLanguage |
static MyResBundle |
messages |
static java.lang.String |
priorMenuLanguage |
static java.io.File[] |
recentFiles
The recentFiles array holds up to 5 pathnames of most-recently opened
SILK files.
|
static java.lang.String |
resourceDirectory |
static int |
saveInterval |
static MyResBundle |
screenElements |
static java.util.ArrayList<Library.ContextStub> |
stubs |
static java.lang.String |
thyDirectory
The default directory (or folder) holding Domain Theory Files (*.thy).
|
static java.lang.String |
userContextName
The name of the current User's default context.
|
static java.lang.String |
userDirectory
The default directory for the current User.
|
static java.util.Locale |
userLocale |
Constructor and Description |
---|
Library() |
Modifier and Type | Method and Description |
---|---|
static void |
addDomainTheory(DomainTheory dt)
Add a new
DomainTheory to the Library. |
static void |
addRecentFile(java.io.File recent) |
static int |
chooseDirectory(KSJInternalFrame window,
java.lang.String title) |
static void |
chooseUserContext(KSJInternalFrame window)
Allow User to choose a new ContextUnderConstruction via a FileChooser.
|
static void |
clusterFVs(int minK,
int maxK,
float penalty)
Do a clustering of all the feature vectors (representing domain theories) in the Library.
|
static java.lang.String |
commafy(int num)
Return a String representing
num with commas separating the thousands, etc. |
static void |
copyFile(java.lang.String oldFileName,
java.lang.String newFileName) |
static void |
createUserContext(KSJInternalFrame window)
Gather the basic information to create a new Context from scratch.
|
static Context |
findOrCreateContext(java.lang.String ctxtName)
Returns a context if already loaded; otherwise retrieves from disk.
|
static java.lang.String[] |
genCtxtMenu()
Return a String array where each array element is the name (28 char max) of a language for a
Context in the Library.
|
static java.lang.String[] |
genCtxtMenu(java.lang.String topChoice) |
static void |
generateAllIndexes(int start,
int end,
java.lang.String suffix)
Build from scratch the Library's ClauseIndex (cbIndex), BaseCBIndex, KinTerm Signature Tree (ktSigTree),
PredEncodings, PredDecodings, and ClauseCounts (cbCounts) for every selected language.
|
static void |
generateSimMatrix()
Generate a Similarity Matrix for all FeatureVectors in the Library.
|
static void |
generateSimMatrix(Library.ClusterState cluSt) |
static java.lang.String[] |
genLangMenu()
Return a String array where each array element is the name of a language for a
domain theory in the Library.
|
static java.util.ArrayList<MyResBundle> |
getElements() |
static void |
getLangCodes() |
static void |
loadNewDomTh(java.io.File file)
Parse a new
DomainTheory from Horn Clauses and add it to the Library. |
static void |
loadSILKFile(java.io.File file)
Read in a .silk file, which is the primary output file of the
KinshipEditor.
|
static int |
nestLength(java.lang.String nested) |
static void |
postDistributions(FeatureVectorObj fv)
Post this Feature Vector's numbers to the totals.
|
static ClauseBody |
readCBfromString(java.lang.String txtCB,
DomainTheory dt) |
static Context |
readContextFromDisk(java.lang.String fileName)
Read an input stream from disk and reconstruct a Context and all its constituents;
by default, add it to the ContextStub file.
|
static Context |
readContextFromDisk(java.lang.String fileName,
boolean makeStub)
Read an input stream from disk & reconstruct a Context and all its
constituents; if makeStub = true, then add it to the ContextStub file.
|
static void |
readDistributionsFromFile()
Read in the Feature Vector distributions from disk.
|
static void |
readStubFile()
Read in the Library's ContextStub array (stubs) from disk.
|
static DomainTheory |
readThyFile(java.lang.String fileName)
Read in a DomainTheory file (in .thy format) from disk.
|
static DomainTheory |
readThyFile(java.lang.String fileName,
boolean allowOverWrite)
Read in a DomainTheory file (in .thy format) from disk.
|
static void |
removeContextStub(Library.ContextStub cs)
Make a new version of the Library's ArrayList
|
static Library.ContextStub |
retrieveOrCreateStub(java.lang.String langName)
Find the ContextStub for this language, or create one.
|
static java.lang.String |
saveContextToDisk(Context ctxt)
Write an output stream to disk that saves the state of the Context and
all its constituents EXCEPT its 2 DomainTheories and its populations.
|
static void |
saveUserContext() |
static void |
saveUserContext(KSJInternalFrame frame,
boolean newName) |
static void |
setStubAdrFileExists(java.lang.String name,
boolean val) |
static java.util.ArrayList<Library.ContextStub> |
stubSort(java.util.ArrayList<Library.ContextStub> stubs)
This is a simple Insertion Sort for alphabetizing ContextStub objects in an ArrayList.
|
static void |
translateReasons(Context ctxt)
Each Marriage has a "reasons" field with text that can be in any valid
language; translate all text into the current menu language.
|
static void |
writeStubFile()
Write out the Library's ArrayList
|
static void |
writeThyFile(DomainTheory dt)
Write out a DomainTheory file in .thy format to location of User's choice
(EXCEPT LIBRARY).
|
public static java.util.TreeMap activeContexts
public static java.lang.String libraryDirectory
public static java.lang.String libraryCtxtDirectory
public static java.lang.String thyDirectory
public static java.lang.String userDirectory
public static java.lang.String editDirectory
public static java.lang.String resourceDirectory
public static java.lang.String helpDirectory
public static MyResBundle menuItems
public static MyResBundle messages
public static MyResBundle screenElements
public static java.util.Locale userLocale
public static java.lang.String userContextName
public static java.lang.String currDataAuthor
public static java.lang.String menuLanguage
public static java.lang.String priorMenuLanguage
public static java.util.ArrayList<Library.ContextStub> stubs
public static Context contextUnderConstruction
public static java.io.File[] recentFiles
public static java.lang.String currentLanguage
public static java.util.ArrayList<java.lang.String> langCodes
public static int saveInterval
public static int changeCounter
public static java.lang.String commafy(int num)
num
with commas separating the thousands, etc.num
- the number to be 'comified.'public static void readStubFile() throws JavaSystemException
JavaSystemException
- if files are corrupted or missing.public static void addRecentFile(java.io.File recent)
public static void chooseUserContext(KSJInternalFrame window) throws JavaSystemException
window
- the current SILKin main window in which the file chooser dialog should be displayed.JavaSystemException
- if file is corrupted or missing.public static void createUserContext(KSJInternalFrame window) throws JavaSystemException
window
- the current SILKin main window, in which the file chooser dialog should be displayed.JavaSystemException
- if file is corrupted or missing.public static int chooseDirectory(KSJInternalFrame window, java.lang.String title)
public static void saveUserContext(KSJInternalFrame frame, boolean newName) throws java.io.NotSerializableException, java.io.IOException, java.io.FileNotFoundException, KSInternalErrorException, KSDateParseException
java.io.NotSerializableException
java.io.IOException
java.io.FileNotFoundException
KSInternalErrorException
KSDateParseException
public static void saveUserContext() throws java.io.NotSerializableException, java.io.IOException, java.io.FileNotFoundException, KSInternalErrorException
java.io.NotSerializableException
java.io.IOException
java.io.FileNotFoundException
KSInternalErrorException
public static java.util.ArrayList<Library.ContextStub> stubSort(java.util.ArrayList<Library.ContextStub> stubs)
stubs
- an ArrayListpublic static void setStubAdrFileExists(java.lang.String name, boolean val)
public static void writeStubFile() throws JavaSystemException
JavaSystemException
public static void removeContextStub(Library.ContextStub cs)
cs
- one element of the ContextStub array.public static int nestLength(java.lang.String nested)
public static ClauseBody readCBfromString(java.lang.String txtCB, DomainTheory dt) throws KSInternalErrorException, JavaSystemException, KSParsingErrorException
public static DomainTheory readThyFile(java.lang.String fileName) throws KSParsingErrorException, JavaSystemException, KSBadHornClauseException, KSInternalErrorException, KSConstraintInconsistency
fileName
- name of file holding the domain theoryJavaSystemException
- if file is corrupted or missing.KSParsingErrorException
- if .thy file cannot be parsed cleanly.KSBadHornClauseException
- if file contains a troublesome Horn clauses.KSConstraintInconsistency
- if constraints in a Horn clause are contradictory.KSInternalErrorException
public static DomainTheory readThyFile(java.lang.String fileName, boolean allowOverWrite) throws KSParsingErrorException, JavaSystemException, KSBadHornClauseException, KSInternalErrorException, KSConstraintInconsistency
fileName
- name of file holding the domain theoryallowOverWrite
- true when we are looking for a possible updateJavaSystemException
- if file is corrupted or missing.KSParsingErrorException
- if .thy file cannot be parsed cleanly.KSBadHornClauseException
- if file contains a troublesome Horn clauses.KSConstraintInconsistency
- if constraints in a Horn clause are contradictory.KSInternalErrorException
public static void writeThyFile(DomainTheory dt) throws JavaSystemException, KSInternalErrorException
dt
- the domain theory to be written.JavaSystemException
- if file is corrupted or missing.KSInternalErrorException
- if the system gets confused and needs a nap.public static java.lang.String saveContextToDisk(Context ctxt) throws java.io.NotSerializableException, java.io.IOException, java.io.FileNotFoundException, KSInternalErrorException
ctxt
- a Context containing the current state of Data_Gatheringjava.io.NotSerializableException
- if any part of the Context is not serializable.java.io.FileNotFoundException
- if the file name is messed up.java.io.IOException
- if there is a generic read/write failure.KSInternalErrorException
public static Context readContextFromDisk(java.lang.String fileName) throws java.io.IOException, java.io.FileNotFoundException, java.lang.ClassNotFoundException
fileName
- a Context containing the current state of Data_Gatheringjava.io.FileNotFoundException
- if the named file does not exist.java.io.IOException
- if there is a generic read/write failure.java.lang.ClassNotFoundException
- if a constructor cannot be found for a class stored in the file .public static Context readContextFromDisk(java.lang.String fileName, boolean makeStub) throws java.io.IOException, java.io.FileNotFoundException, java.lang.ClassNotFoundException
fileName
- a Context containing the current state of Data_GatheringmakeStub
- true = add this context to the ContextStub file.java.io.FileNotFoundException
- if the named file does not exist.java.io.IOException
- if there is a generic read/write failure.java.lang.ClassNotFoundException
- if a constructor cannot be found for a class stored in the file .public static Context findOrCreateContext(java.lang.String ctxtName) throws java.io.FileNotFoundException
ctxtName
- name of the contextjava.io.FileNotFoundException
- if no such context is found in the Contexts folder of current Library.public static void copyFile(java.lang.String oldFileName, java.lang.String newFileName) throws KSInternalErrorException, java.io.IOException
KSInternalErrorException
java.io.IOException
public static void loadNewDomTh(java.io.File file) throws KSParsingErrorException, JavaSystemException, KSConstraintInconsistency, java.io.NotSerializableException, KSBadHornClauseException, KSInternalErrorException, java.io.IOException
DomainTheory
from Horn Clauses and add it to the Library.
If there's no existing context for this language, make one.file
- a text file containing Horn Clauses expressing a Domain Theory{@link
- KSInternalErrorException} if dt
would over-write an existing domain theory.{@link
- KSBadHornClauseException} if the theory contains an illegal or contradictory clause.{@link
- JavaSystemException} if writing the final *.thy file gets an IO Exception{@link
- KSParsingErrorException} if the file cannot be parsed.KSParsingErrorException
JavaSystemException
KSConstraintInconsistency
java.io.NotSerializableException
KSBadHornClauseException
KSInternalErrorException
java.io.IOException
public static void loadSILKFile(java.io.File file) throws KSParsingErrorException, JavaSystemException, java.io.IOException, KSBadHornClauseException, KSInternalErrorException, KSConstraintInconsistency, KSDateParseException
file
- the .silk file{@link
- JavaSystemException} if reading any file gets an IO ExceptionKSParsingErrorException
JavaSystemException
java.io.IOException
KSBadHornClauseException
KSInternalErrorException
KSConstraintInconsistency
KSDateParseException
public static void translateReasons(Context ctxt)
ctxt
- the context to be translatedpublic static void getLangCodes()
public static java.util.ArrayList<MyResBundle> getElements()
public static void addDomainTheory(DomainTheory dt) throws KSInternalErrorException, KSBadHornClauseException, KSParsingErrorException, JavaSystemException, java.io.NotSerializableException, java.io.IOException
DomainTheory
to the Library. If there's no existing context for this language, make one.
Save (or re-save) the context to disk after updating it.dt
- a Domain Theory to be loaded{@link
- KSInternalErrorException} if dt
would over-write an existing domain theory.{@link
- KSBadHornClauseException} if the theory contains an illegal or contradictory clause.{@link
- JavaSystemException} if writing the final *.thy file gets an IO ExceptionKSInternalErrorException
KSBadHornClauseException
KSParsingErrorException
JavaSystemException
java.io.NotSerializableException
java.io.IOException
public static Library.ContextStub retrieveOrCreateStub(java.lang.String langName)
langName
- name of the language for the desired contextpublic static java.lang.String[] genLangMenu()
public static java.lang.String[] genCtxtMenu()
public static java.lang.String[] genCtxtMenu(java.lang.String topChoice)
public static void generateAllIndexes(int start, int end, java.lang.String suffix) throws KSInternalErrorException, JavaSystemException, KSParsingErrorException, KSBadHornClauseException, KSConstraintInconsistency, java.lang.ClassNotFoundException, java.io.IOException
KSInternalErrorException
JavaSystemException
KSParsingErrorException
KSBadHornClauseException
KSConstraintInconsistency
java.lang.ClassNotFoundException
java.io.IOException
public static void generateSimMatrix() throws KSBadHornClauseException, KSInternalErrorException, KSConstraintInconsistency, java.lang.ClassNotFoundException, java.io.IOException, JavaSystemException
KSBadHornClauseException
KSInternalErrorException
KSConstraintInconsistency
java.lang.ClassNotFoundException
java.io.IOException
JavaSystemException
public static void generateSimMatrix(Library.ClusterState cluSt) throws KSBadHornClauseException, KSInternalErrorException, KSConstraintInconsistency, java.lang.ClassNotFoundException, java.io.IOException, JavaSystemException
KSBadHornClauseException
KSInternalErrorException
KSConstraintInconsistency
java.lang.ClassNotFoundException
java.io.IOException
JavaSystemException
public static void postDistributions(FeatureVectorObj fv)
fv
- a FeatureVector whose elements are to be posted to the totals
stored in static elements of the FeatureVectorObj
classpublic static void readDistributionsFromFile() throws JavaSystemException
JavaSystemException
- if file system gets in trouble.public static void clusterFVs(int minK, int maxK, float penalty) throws KSBadHornClauseException, KSInternalErrorException, KSConstraintInconsistency, java.lang.ClassNotFoundException, java.io.IOException, JavaSystemException
For k = minK to maxK do
Set "equal impact" weights on each of the F features (normalized by variance of feature distances)
Pick initial seeds c_1 ... c_k. whose distance to each other is >= median.
Calculate Squared Euclidian Distance matrix for the DTs
Do K-medioids clustering using distance of newbie to seed-or-medioid
Iteratively alter the weights on each feature to maximize cluster quality.
Cluster Quality = - Sum_over_all_x,y[ b * dist(x, y)] + Lopsided-Weight-Penalty
where b = 1 if x & y are in same the cluster or -1 otherwise
Re-cluster with the new weight vector.
Repeat until clustering does not change.
Store the best clustering and its quality score.
Pick the k (and weight vector) which has the best quality score.
minK
- the smallest number of clusters desiredmaxK
- the largest number of clusters desiredpenalty
- the percentage of a cluster's quality score which is subtracted if all the feature weight is
given to a single feature.JavaSystemException
- if file system gets in trouble.KSInternalErrorException
- if the code gets hung upKSBadHornClauseException
- if the generation of a Similarity Matrix hits a troublesome Horn clausejava.io.IOException
- if file system activity encounteredjava.lang.ClassNotFoundException
- if class can't be foundKSConstraintInconsistency
- if the generation of a Similarity Matrix hits troublesome constrints in a Horn clause