Revision: 16333
http://gate.svn.sourceforge.net/gate/?rev=16333&view=rev
Author: adamfunk
Date: 2012-11-27 10:54:07 +0000 (Tue, 27 Nov 2012)
Log Message:
-----------
deleting project-specific cruft from TR
Modified Paths:
--------------
gate/trunk/plugins/TermRaider/applications/termraider-eng.gapp
gate/trunk/plugins/TermRaider/applications/termraider-multilingual.gapp
gate/trunk/plugins/TermRaider/resources/groovy/DeduplicateMultiWord.groovy
gate/trunk/plugins/TermRaider/src/gate/termraider/bank/AbstractTermbank.java
gate/trunk/plugins/TermRaider/src/gate/termraider/util/AbstractBank.java
Removed Paths:
-------------
gate/trunk/plugins/TermRaider/src/gate/termraider/gui/ActionMakeOntology.java
gate/trunk/plugins/TermRaider/src/gate/termraider/gui/ActionSaveRdf.java
gate/trunk/plugins/TermRaider/src/gate/termraider/output/OntologyGenerator.java
Modified: gate/trunk/plugins/TermRaider/applications/termraider-eng.gapp
===================================================================
--- gate/trunk/plugins/TermRaider/applications/termraider-eng.gapp
2012-11-27 02:19:08 UTC (rev 16332)
+++ gate/trunk/plugins/TermRaider/applications/termraider-eng.gapp
2012-11-27 10:54:07 UTC (rev 16333)
@@ -11,21 +11,15 @@
<urlString>$relpath$../../Tools/</urlString>
</gate.util.persistence.PersistenceManager-URLHolder>
<gate.util.persistence.PersistenceManager-URLHolder>
- <urlString>$relpath$../../Ontology/</urlString>
- </gate.util.persistence.PersistenceManager-URLHolder>
- <gate.util.persistence.PersistenceManager-URLHolder>
<urlString>$relpath$../../Groovy/</urlString>
</gate.util.persistence.PersistenceManager-URLHolder>
- <gate.util.persistence.PersistenceManager-URLHolder>
- <urlString>$relpath$../../Ontology_Tools/</urlString>
- </gate.util.persistence.PersistenceManager-URLHolder>
</localList>
<collectionType>java.util.ArrayList</collectionType>
</urlList>
<application class="gate.groovy.ScriptableControllerPersistence">
<controlScript class="string">import gate.termraider.*;
-String instNamespace =
gate.termraider.output.OntologyGenerator.generateInstanceNamespace();
+String instNamespace =
gate.termraider.util.AbstractBank.generateInstanceNamespace();
// equivalent to old preprocessor
eachDocument {
Modified:
gate/trunk/plugins/TermRaider/applications/termraider-multilingual.gapp
===================================================================
--- gate/trunk/plugins/TermRaider/applications/termraider-multilingual.gapp
2012-11-27 02:19:08 UTC (rev 16332)
+++ gate/trunk/plugins/TermRaider/applications/termraider-multilingual.gapp
2012-11-27 10:54:07 UTC (rev 16333)
@@ -11,15 +11,9 @@
<urlString>$relpath$../../Tools/</urlString>
</gate.util.persistence.PersistenceManager-URLHolder>
<gate.util.persistence.PersistenceManager-URLHolder>
- <urlString>$relpath$../../Ontology/</urlString>
- </gate.util.persistence.PersistenceManager-URLHolder>
- <gate.util.persistence.PersistenceManager-URLHolder>
<urlString>$relpath$../../Groovy/</urlString>
</gate.util.persistence.PersistenceManager-URLHolder>
<gate.util.persistence.PersistenceManager-URLHolder>
- <urlString>$relpath$../../Ontology_Tools/</urlString>
- </gate.util.persistence.PersistenceManager-URLHolder>
- <gate.util.persistence.PersistenceManager-URLHolder>
<urlString>$relpath$../../Language_Identification/</urlString>
</gate.util.persistence.PersistenceManager-URLHolder>
</localList>
@@ -28,7 +22,7 @@
<application class="gate.groovy.ScriptableControllerPersistence">
<controlScript class="string">import gate.termraider.*;
-String instNamespace =
gate.termraider.output.OntologyGenerator.generateInstanceNamespace();
+String instNamespace =
gate.termraider.util.AbstractBank.generateInstanceNamespace();
// equivalent to old preprocessor
eachDocument {
Modified:
gate/trunk/plugins/TermRaider/resources/groovy/DeduplicateMultiWord.groovy
===================================================================
--- gate/trunk/plugins/TermRaider/resources/groovy/DeduplicateMultiWord.groovy
2012-11-27 02:19:08 UTC (rev 16332)
+++ gate/trunk/plugins/TermRaider/resources/groovy/DeduplicateMultiWord.groovy
2012-11-27 10:54:07 UTC (rev 16333)
@@ -52,21 +52,12 @@
inputAS.remove(candidate);
}
- if (! gate.Utils.getContainedAnnotations(inputAS, candidate,
"StrongStop").isEmpty()) {
+ else if (! gate.Utils.getContainedAnnotations(inputAS, candidate,
"StrongStop").isEmpty()) {
FeatureMap newf = Factory.newFeatureMap();
newf.putAll(candidate.getFeatures());
String newType = "deleted_SS_" + candidate.getType();
inputAS.add(candidate.getStartNode(), candidate.getEndNode(), newType,
newf);
inputAS.remove(candidate);
}
-
- // suppress Greek tokens that slip through
- else if (gate.termraider.util.Utilities.greekness(candidate, "canonical") >
0.0) {
- FeatureMap newf = Factory.newFeatureMap();
- newf.putAll(candidate.getFeatures());
- String newType = "deleted_Gk_" + candidate.getType();
- inputAS.add(candidate.getStartNode(), candidate.getEndNode(), newType,
newf);
- inputAS.remove(candidate);
- }
}
Modified:
gate/trunk/plugins/TermRaider/src/gate/termraider/bank/AbstractTermbank.java
===================================================================
---
gate/trunk/plugins/TermRaider/src/gate/termraider/bank/AbstractTermbank.java
2012-11-27 02:19:08 UTC (rev 16332)
+++
gate/trunk/plugins/TermRaider/src/gate/termraider/bank/AbstractTermbank.java
2012-11-27 10:54:07 UTC (rev 16333)
@@ -13,7 +13,6 @@
import gate.creole.*;
import gate.creole.metadata.*;
-import gate.creole.ontology.*;
import gate.gui.ActionsPublisher;
import gate.util.*;
import gate.*;
@@ -134,8 +133,6 @@
protected void createActions() {
actionsList = new ArrayList<Action>();
- actionsList.add(new ActionMakeOntology("Generate GATE Ontology...
(EXPERIMENTAL)", this));
- actionsList.add(new ActionSaveRdf("Save as RDF-XML... (EXPERIMENTAL)",
this));
actionsList.add(new ActionSaveCsv("Save as CSV...", this));
}
@@ -228,115 +225,6 @@
- /* Methods for generating a GATE ontology */
- public void makeOntology(double threshold, String ontologyName, String
instanceNamespace) throws GateException {
- OntologyGenerator generator = new OntologyGenerator(this);
- generator.generateOntology(threshold, ontologyName, instanceNamespace);
- }
-
- public Ontology makeOntology(String ontologyName,
- String instanceNamespace) throws GateException {
- double threshold = this.getMinScore();
- OntologyGenerator generator = new OntologyGenerator(this);
- return generator.generateOntology(threshold, ontologyName,
instanceNamespace);
- }
-
- public Ontology makeOntology(String ontologyName, float topPart) throws
GateException {
- double threshold = this.getMaxScore();
- if (topPart >= 1.0F) {
- threshold = this.getMinScore();
- }
- else if (topPart >= 0.0F) {
- threshold = this.getMaxScore() - (this.getMaxScore() -
this.getMinScore()) * topPart;
- }
-
- OntologyGenerator generator = new OntologyGenerator(this);
- if ( (this.namespaceBase == null) || this.namespaceBase.isEmpty() ) {
- return generator.generateOntology(threshold, ontologyName, null);
- }
- else {
- return generator.generateOntology(threshold, ontologyName,
this.namespaceBase);
- }
- }
-
-
- public Ontology makeOntology(String ontologyName) throws GateException {
- double threshold = this.getMinScore();
- OntologyGenerator generator = new OntologyGenerator(this);
- if ( (this.namespaceBase == null) || this.namespaceBase.isEmpty() ) {
- return generator.generateOntology(threshold, ontologyName, null);
- }
- else {
- return generator.generateOntology(threshold, ontologyName,
this.namespaceBase);
- }
- }
-
-
- /* Methods for saving as RDF-XML */
-
- public Ontology saveAsRdf(double threshold, File outputFile) throws
GateException {
- OntologyGenerator generator = new OntologyGenerator(this);
- Ontology ontology = generator.generateOntology(threshold,
- this.getName() + "_ontology",
OntologyGenerator.generateInstanceNamespace());
- FileWriter outputWriter;
- try {
- outputWriter = new FileWriter(outputFile);
- ontology.writeOntologyData(outputWriter,
OConstants.OntologyFormat.RDFXML, false);
- if (debugMode) {
- System.out.println("Termbank: saved RDF in " +
outputFile.getAbsolutePath());
- }
- outputWriter.flush();
- outputWriter.close();
- }
- catch(IOException e) {
- throw new GateException(e);
- }
- return ontology;
- }
-
-
- public Ontology writeRdf(double threshold, OutputStream stream) throws
GateException {
- try {
- OntologyGenerator generator = new OntologyGenerator(this);
- Ontology ontology = generator.generateOntology(threshold,
- this.getName() + "_ontology",
OntologyGenerator.generateInstanceNamespace());
- ontology.writeOntologyData(stream, OConstants.OntologyFormat.RDFXML,
false);
- stream.flush();
- return ontology;
- }
- catch (IOException e) {
- throw new GateException(e);
- }
- }
-
-
- /**
- * Convenience method to save everything in the termbank.
- * @param outputFile
- * @throws GateException
- */
- public Ontology saveAsRdf(File outputFile) throws GateException {
- double threshold = this.getMinScore();
- return this.saveAsRdf(threshold, outputFile);
- }
-
- public void saveAsRdfAndDeleteOntology(File outputFile) throws GateException
{
- Ontology ontology = this.saveAsRdf(outputFile);
- Factory.deleteResource(ontology);
- }
-
- public void saveAsRdfAndDeleteOntology(double threshold, File outputFile)
throws GateException {
- Ontology ontology = this.saveAsRdf(threshold, outputFile);
- Factory.deleteResource(ontology);
- }
-
- public void writeRdfAndDeleteOntology(double threshold, OutputStream stream)
- throws GateException {
- Ontology ontology = this.writeRdf(threshold, stream);
- Factory.deleteResource(ontology);
- }
-
-
/* Methods for saving as CSV */
public void saveAsCsv(double threshold, File outputFile) throws
GateException {
Deleted:
gate/trunk/plugins/TermRaider/src/gate/termraider/gui/ActionMakeOntology.java
===================================================================
---
gate/trunk/plugins/TermRaider/src/gate/termraider/gui/ActionMakeOntology.java
2012-11-27 02:19:08 UTC (rev 16332)
+++
gate/trunk/plugins/TermRaider/src/gate/termraider/gui/ActionMakeOntology.java
2012-11-27 10:54:07 UTC (rev 16333)
@@ -1,146 +0,0 @@
-/*
- * Copyright (c) 2008--2012, The University of Sheffield. See the file
- * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
- *
- * This file is part of GATE (see http://gate.ac.uk/), and is free
- * software, licenced under the GNU Library General Public License,
- * Version 2, June 1991 (in the distribution as file licence.html,
- * and also available at http://gate.ac.uk/gate/licence.html).
- *
- * $Id$
- */
-package gate.termraider.gui;
-
-import gate.gui.MainFrame;
-import gate.util.GateException;
-import java.awt.BorderLayout;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import javax.swing.*;
-import gate.termraider.bank.*;
-import gate.termraider.output.*;
-
-
-/**
- * Action class for saving an ontology from the GATE GUI.
- */
-public class ActionMakeOntology
- extends AbstractAction {
-
-
- private static final long serialVersionUID = -1135800259696959339L;
-
- private AbstractTermbank termbank;
-
- public ActionMakeOntology(String label, AbstractTermbank termbank) {
- super(label);
- this.termbank = termbank;
- }
-
- public void actionPerformed(ActionEvent ae) {
- JDialog ontologyDialog = new JDialog(MainFrame.getInstance(), "Generate an
ontology from this Termbank (EXPERIMENTAL)", true);
- MainFrame.getGuiRoots().add(ontologyDialog);
- ontologyDialog.setLayout(new BorderLayout());
- SliderPanel sliderPanel = new SliderPanel(termbank, "populate the
ontology", true, null);
- ontologyDialog.add(sliderPanel, BorderLayout.CENTER);
-
- JPanel underPanel = new JPanel();
- underPanel.setLayout(new BoxLayout(underPanel, BoxLayout.Y_AXIS));
- underPanel.add(new JSeparator());
- underPanel.add(Box.createVerticalStrut(5));
- underPanel.add(new JLabel("The following parameters can be edited (default
values are provided):"));
- underPanel.add(Box.createVerticalStrut(5));
-
- JPanel stringsPanel = new JPanel(new GridBagLayout());
- Insets insets = new Insets(0, 0, 0, 0);
-
- JLabel ontologyNameLabel = new JLabel("Ontology name");
- stringsPanel.add(ontologyNameLabel, new GridBagConstraints(0, 0, 1, 1,
0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, insets, 1, 1));
- JTextField nameField = new JTextField("", 50);
- String defaultOntologyName = termbank.getName() + "_ontology";
- nameField.setText(defaultOntologyName);
- nameField.setToolTipText("name of the GATE Ontology LR to be created");
- stringsPanel.add(nameField, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.NONE, insets, 1, 1));
-
- JLabel instanceNamespaceLabel = new JLabel("Namespace for instances");
- stringsPanel.add(instanceNamespaceLabel, new GridBagConstraints(0, 1, 1,
1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, insets, 1, 1));
-
- JTextField instanceNamespaceField = new JTextField("", 50);
- if ( (termbank.getNamespaceBase() == null) ||
termbank.getNamespaceBase().isEmpty()) {
-
instanceNamespaceField.setText(OntologyGenerator.generateInstanceNamespace());
- }
- else {
- instanceNamespaceField.setText(termbank.getNamespaceBase());
- }
- instanceNamespaceField.setToolTipText("Ontology namespaces for instances
(terms)");
- stringsPanel.add(instanceNamespaceField, new GridBagConstraints(1, 1, 1,
1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, insets, 1, 1));
-
- underPanel.add(stringsPanel);
- underPanel.add(Box.createVerticalStrut(5));
-
- Box buttonBox = Box.createHorizontalBox();
- buttonBox.add(Box.createHorizontalGlue());
- JButton okButton = new JButton(OntologyActionListener.okAction);
- buttonBox.add(okButton);
- buttonBox.add(Box.createHorizontalGlue());
- JButton cancelButton = new JButton(OntologyActionListener.cancelAction);
- buttonBox.add(cancelButton);
- buttonBox.add(Box.createHorizontalGlue());
- underPanel.add(buttonBox);
-
- OntologyActionListener listener = new OntologyActionListener(termbank,
sliderPanel, ontologyDialog,
- nameField, instanceNamespaceField);
- okButton.addActionListener(listener);
- cancelButton.addActionListener(listener);
-
- ontologyDialog.add(underPanel, BorderLayout.SOUTH);
- ontologyDialog.pack();
- ontologyDialog.setLocationRelativeTo(ontologyDialog.getOwner());
- ontologyDialog.setVisible(true);
- }
-}
-
-
-class OntologyActionListener implements ActionListener {
-
- private AbstractTermbank termbank;
- private SliderPanel sliderPanel;
- private JDialog dialog;
- private JTextField nameField, instanceNamespaceField;
- public static String okAction = "OK";
- public static String cancelAction = "Cancel";
-
- public OntologyActionListener(AbstractTermbank termbank, SliderPanel
sliderPanel, JDialog dialog,
- JTextField nameField, JTextField instanceNamespaceField) {
- this.termbank = termbank;
- this.sliderPanel = sliderPanel;
- this.dialog = dialog;
- this.nameField = nameField;
- this.instanceNamespaceField = instanceNamespaceField;
- }
-
- @Override
- public void actionPerformed(ActionEvent event) {
- if (event.getActionCommand().equals(okAction)) {
- try {
- String oName = nameField.getText();
- if (oName.isEmpty()) {
- oName = nameField.getToolTipText();
- }
- termbank.makeOntology(sliderPanel.getValues(), oName,
instanceNamespaceField.getText());
- }
- catch(GateException e) {
- e.printStackTrace();
- }
- finally {
- dialog.dispose();
- }
- }
- else if (event.getActionCommand().equals(cancelAction)) {
- dialog.dispose();
- }
- }
-}
Deleted:
gate/trunk/plugins/TermRaider/src/gate/termraider/gui/ActionSaveRdf.java
===================================================================
--- gate/trunk/plugins/TermRaider/src/gate/termraider/gui/ActionSaveRdf.java
2012-11-27 02:19:08 UTC (rev 16332)
+++ gate/trunk/plugins/TermRaider/src/gate/termraider/gui/ActionSaveRdf.java
2012-11-27 10:54:07 UTC (rev 16333)
@@ -1,100 +0,0 @@
-/*
- * Copyright (c) 2008--2012, The University of Sheffield. See the file
- * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
- *
- * This file is part of GATE (see http://gate.ac.uk/), and is free
- * software, licenced under the GNU Library General Public License,
- * Version 2, June 1991 (in the distribution as file licence.html,
- * and also available at http://gate.ac.uk/gate/licence.html).
- *
- * $Id$
- */
-package gate.termraider.gui;
-
-import gate.gui.MainFrame;
-import gate.util.GateException;
-import java.awt.BorderLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import javax.swing.*;
-import gate.termraider.bank.*;
-import gate.termraider.util.Utilities;
-
-import java.io.*;
-import javax.swing.filechooser.FileNameExtensionFilter;
-
-
-/**
- * Action class for saving RDF-XML from the GATE GUI.
- */
-public class ActionSaveRdf
- extends AbstractAction {
-
- private static final long serialVersionUID = 5725028061478144129L;
-
- private AbstractTermbank termbank;
-
- public ActionSaveRdf(String label, AbstractTermbank termbank) {
- super(label);
- this.termbank = termbank;
- }
-
- public void actionPerformed(ActionEvent ae) {
- JDialog saveDialog = new JDialog(MainFrame.getInstance(), "Save Termbank
as RDF-XML (EXPERIMENTAL)", true);
- MainFrame.getGuiRoots().add(saveDialog);
- saveDialog.setLayout(new BorderLayout());
- SliderPanel sliderPanel = new SliderPanel(termbank, "save", true, null);
- saveDialog.add(sliderPanel, BorderLayout.CENTER);
-
- JPanel chooserPanel = new JPanel();
- chooserPanel.setLayout(new BoxLayout(chooserPanel, BoxLayout.Y_AXIS));
- chooserPanel.add(new JSeparator());
-
- JFileChooser chooser = new JFileChooser();
- FileNameExtensionFilter filter = new FileNameExtensionFilter("RDF-XML
files", Utilities.EXTENSION_RDF, "xml");
- chooser.setFileFilter(filter);
- chooser.setApproveButtonText("Save");
- chooser.addActionListener(new RdfFileSelectionActionListener(chooser,
termbank, sliderPanel, saveDialog));
- chooserPanel.add(chooser);
- saveDialog.add(chooserPanel, BorderLayout.SOUTH);
- saveDialog.pack();
- saveDialog.setLocationRelativeTo(saveDialog.getOwner());
- saveDialog.setVisible(true);
- }
-}
-
-
-class RdfFileSelectionActionListener implements ActionListener {
-
- private JFileChooser chooser;
- private AbstractTermbank termbank;
- private SliderPanel sliderPanel;
- private JDialog dialog;
-
- public RdfFileSelectionActionListener(JFileChooser chooser, AbstractTermbank
termbank, SliderPanel sliderPanel, JDialog dialog) {
- this.chooser = chooser;
- this.termbank = termbank;
- this.sliderPanel = sliderPanel;
- this.dialog = dialog;
- }
-
- @Override
- public void actionPerformed(ActionEvent event) {
- if (event.getActionCommand().equals(JFileChooser.APPROVE_SELECTION)) {
- File outputFile =
Utilities.addExtensionIfNotExtended(chooser.getSelectedFile(),
- Utilities.EXTENSION_RDF);
- try {
- termbank.saveAsRdf(sliderPanel.getValues(), outputFile);
- }
- catch(GateException e) {
- e.printStackTrace();
- }
- finally {
- dialog.dispose();
- }
- }
- else if (event.getActionCommand().equals(JFileChooser.CANCEL_SELECTION)) {
- dialog.dispose();
- }
- }
-}
Deleted:
gate/trunk/plugins/TermRaider/src/gate/termraider/output/OntologyGenerator.java
===================================================================
---
gate/trunk/plugins/TermRaider/src/gate/termraider/output/OntologyGenerator.java
2012-11-27 02:19:08 UTC (rev 16332)
+++
gate/trunk/plugins/TermRaider/src/gate/termraider/output/OntologyGenerator.java
2012-11-27 10:54:07 UTC (rev 16333)
@@ -1,185 +0,0 @@
-/*
- * Copyright (c) 2010--2012, The University of Sheffield. See the file
- * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
- *
- * This file is part of GATE (see http://gate.ac.uk/), and is free
- * software, licenced under the GNU Library General Public License,
- * Version 2, June 1991 (in the distribution as file licence.html,
- * and also available at http://gate.ac.uk/gate/licence.html).
- *
- * $Id$
- */
-package gate.termraider.output;
-
-import gate.*;
-import gate.creole.*;
-import gate.creole.ontology.*;
-import gate.util.GateException;
-import java.net.*;
-import java.util.*;
-import gate.termraider.bank.*;
-import gate.termraider.util.*;
-
-
-public class OntologyGenerator {
-
- String xmlBaseFilePath = "gate/resources/base_ontology.rdf";
-
- public static final String rdfUri =
"http://www.w3.org/1999/02/22-rdf-syntax-ns#";
- public static final String rdfsUri =
"http://www.w3.org/2000/01/rdf-schema#";
- public static final String xsdUri = "http://www.w3.org/2001/XMLSchema#";
- public static final String arcoUri =
"http://www.gate.ac.uk/ns/ontologies/arcomem-data-model.rdf#";
- public static final String randomNsBase =
"http://www.gate.ac.uk/ns/arcomem/";
- public static final String ontologyClass =
"gate.creole.ontology.impl.sesame.OWLIMOntology";
-
- private String instanceNamespaceUri;
-
- private AnnotationProperty labelProperty;
- private DatatypeProperty scoreProperty, freqProperty, languageProperty;
- private ObjectProperty isRealizedByProperty;
- private OClass termClass, textClass;
- private boolean debugMode;
- private AbstractTermbank termbank;
- private String scorePropertyName, freqPropertyName, languagePropertyName;
-
-
- public OntologyGenerator(AbstractTermbank termbank) {
- this.termbank = termbank;
- this.debugMode = termbank.getDebugMode();
- this.scorePropertyName = termbank.getScoreProperty();
- this.freqPropertyName = termbank.getFreqProperty();
- this.languagePropertyName = "hasLanguage";
- }
-
-
- public static String generateInstanceNamespace() {
- return Utilities.generateID(randomNsBase, "#");
- }
-
-
- public Ontology generateOntology(double threshold, String ontologyName,
- String specifiedInstanceNamespace) throws
ResourceInstantiationException {
- Ontology ontology = loadBaseOntology();
- initializeOntology(ontology, ontologyName, specifiedInstanceNamespace);
- try {
- populateOntology(ontology, threshold);
- }
- catch(InvalidValueException e) {
- throw new ResourceInstantiationException(e);
- }
- return ontology;
- }
-
-
- private Ontology loadBaseOntology() throws ResourceInstantiationException {
- FeatureMap parameters = Factory.newFeatureMap();
- URL baseUrl = Utilities.getUrlInJar(termbank, xmlBaseFilePath);
- parameters.put("rdfXmlURL", baseUrl);
- Resource ontology = Factory.createResource(ontologyClass, parameters);
- return (Ontology) ontology;
- }
-
-
- private void populateOntology(Ontology ontology, double threshold) throws
InvalidValueException {
- Map<Term, Double> termScores = termbank.getTermScores();
- Map<Term, Set<String>> termDocuments = termbank.getTermDocuments();
- List<Term> sortedTerms = termbank.getTermsByDescendingScore();
-
- int written = 0;
-
- for (Term term : sortedTerms) {
- Double score = termScores.get(term);
- if (score >= threshold) {
- Set<String> documents = termDocuments.get(term);
- makeTermInstance(ontology, term, score, documents);
- written++;
- }
- else { // the rest must be lower
- break;
- }
- }
- }
-
-
- private OInstance makeTermInstance(Ontology ontology, Term term,
- Double score, Set<String> documents) throws InvalidValueException {
- String flattenedTermName =
Utilities.veryCleanString(term.getTermString());
- OURI termUri = ontology.createOURI(instanceNamespaceUri +
flattenedTermName);
- OInstance termInstance = ontology.addOInstance(termUri, this.termClass);
- termInstance.addAnnotationPropertyValue(labelProperty, new
Literal(term.getTermString(), DataType.getStringDataType()));
- termInstance.addDatatypePropertyValue(scoreProperty, new
Literal(score.toString(), DataType.getDoubleDataType()));
- termInstance.addDatatypePropertyValue(languageProperty, new
Literal(term.getLanguageCode(), DataType.getStringDataType()));
-
- for (String document: documents) {
- OURI textInstanceUri = ontology.createOURI(instanceNamespaceUri +
Utilities.generateID("Text_", ""));
- OInstance textInstance = ontology.addOInstance(textInstanceUri,
this.textClass);
- textInstance.addAnnotationPropertyValue(labelProperty, new
Literal(document, DataType.getStringDataType()));
- termInstance.addObjectPropertyValue(isRealizedByProperty, textInstance);
- }
-
- if (freqProperty != null) {
- int frequency = this.termbank.getTermFrequency(term);
- termInstance.addDatatypePropertyValue(freqProperty, new
Literal(Integer.toString(frequency), DataType.getIntDataType()));
- }
-
- return termInstance;
- }
-
-
- private void initializeOntology(Ontology ontology, String ontologyName,
- String specifiedInstanceNamespace) {
- if ( (specifiedInstanceNamespace == null) ||
specifiedInstanceNamespace.isEmpty() ) {
- this.instanceNamespaceUri = Utilities.generateID(randomNsBase, "#");
- }
- else {
- this.instanceNamespaceUri = specifiedInstanceNamespace;
- }
-
- OURI termUri = ontology.createOURI(arcoUri + "Term");
- OURI textUri = ontology.createOURI(arcoUri + "Text");
- OURI labelUri = ontology.createOURI(rdfsUri + "label");
- OURI scoreUri = ontology.createOURI(arcoUri + scorePropertyName);
- OURI languageUri = ontology.createOURI(arcoUri + languagePropertyName);
- OURI isRealizedByUri = ontology.createOURI(arcoUri + "isRealizedBy");
-
- this.termClass = ontology.getOClass(termUri);
- Set<OClass> termClassSet = Collections.singleton(this.termClass);
-
- this.textClass = ontology.getOClass(textUri);
- Set<OClass> textClassSet = Collections.singleton(this.textClass);
-
- if ( (freqPropertyName != null) && (! freqPropertyName.isEmpty()) ) {
- OURI freqUri = ontology.createOURI(arcoUri + freqPropertyName);
- this.freqProperty = ontology.addDatatypeProperty(freqUri, termClassSet,
DataType.getIntDataType());
- }
- else {
- this.freqProperty = null;
- }
-
-
- this.labelProperty = ontology.getAnnotationProperty(labelUri);
- this.languageProperty = ontology.addDatatypeProperty(languageUri,
termClassSet, DataType.getStringDataType());
- this.scoreProperty = ontology.addDatatypeProperty(scoreUri, termClassSet,
DataType.getDoubleDataType());
- this.isRealizedByProperty = ontology.addObjectProperty(isRealizedByUri,
termClassSet, textClassSet);
- ontology.setName(ontologyName);
-
- if (debugMode) {
- System.out.println("Termbank -> Ontology: instances " +
this.instanceNamespaceUri);
- }
- }
-
-
-
- protected void setInstanceNamespace(String uri) throws GateException {
- try {
- // make sure it's valid
- new java.net.URI(uri);
- }
- catch(URISyntaxException e) {
- throw new GateException(e);
- }
- instanceNamespaceUri = uri;
- }
-
-
-}
Modified:
gate/trunk/plugins/TermRaider/src/gate/termraider/util/AbstractBank.java
===================================================================
--- gate/trunk/plugins/TermRaider/src/gate/termraider/util/AbstractBank.java
2012-11-27 02:19:08 UTC (rev 16332)
+++ gate/trunk/plugins/TermRaider/src/gate/termraider/util/AbstractBank.java
2012-11-27 10:54:07 UTC (rev 16333)
@@ -17,7 +17,6 @@
import gate.creole.metadata.CreoleParameter;
import gate.util.GateException;
import java.io.File;
-import java.io.OutputStream;
import org.apache.commons.lang.StringUtils;
import java.util.*;
@@ -30,6 +29,8 @@
public abstract class AbstractBank extends AbstractLanguageResource {
private static final long serialVersionUID = -9168657973312733783L;
+ public static final String randomNsBase =
"http://www.gate.ac.uk/ns/arcomem/";
+
protected Set<String> languages, types;
@@ -44,15 +45,6 @@
public abstract void saveAsCsv(File file)
throws GateException;
- public abstract void saveAsRdfAndDeleteOntology(double threshold, File file)
- throws GateException;
-
- public abstract void saveAsRdfAndDeleteOntology(File file)
- throws GateException;
-
- public abstract void writeRdfAndDeleteOntology(double threshold,
OutputStream stream)
- throws GateException;
-
public Set<String> getLanguages() {
return this.languages;
}
@@ -132,5 +124,9 @@
}
+ public static String generateInstanceNamespace() {
+ return Utilities.generateID(randomNsBase, "#");
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs