Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions AgreementMakerLight/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
<classpathentry kind="lib" path="src/lib/jaws.jar"/>
<classpathentry kind="lib" path="src/lib/simmetrics.jar"/>
<classpathentry kind="lib" path="src/lib/gephi-toolkit.jar"/>
<classpathentry kind="lib" path="src/lib/elk.jar"/>
<classpathentry kind="lib" path="src/lib/owlapi.jar"/>
<classpathentry kind="lib" path="src/lib/net.sourceforge.owlapi/pellet-core-ignazio1977/2.4.0-ignazio1977/pellet-core-ignazio1977-2.4.0-ignazio1977.jar"/>
<classpathentry kind="lib" path="src/lib/net.sourceforge.owlapi/pellet-core-ignazio1977/2.4.0-ignazio1977/pellet-owlapi-ignazio1977-2.4.0-ignazio1977.jar"/>
<classpathentry kind="lib" path="src/lib/owlapi-distribution-4.1.3.jar"/>
<classpathentry kind="lib" path="src/lib/log4j.jar"/>
<classpathentry kind="lib" path="src/lib/microsoft-translator.jar"/>
<classpathentry kind="lib" path="src/lib/commons-lang-2.6.jar"/>
Expand Down
61 changes: 53 additions & 8 deletions AgreementMakerLight/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>aml</groupId>
<artifactId>aml</artifactId>
<packaging>jar</packaging>
<version>2.1-SNAPSHOT</version>
<version>2.1-owlapi4</version>

<name>AgreementMakerLight</name>
<url>http://somer.fc.ul.pt/aml.php</url>
Expand All @@ -30,6 +30,11 @@
<checksumPolicy>fail</checksumPolicy>
</releases>
</repository>
<repository>
<id>in-project</id>
<name>In Project Repo</name>
<url>file://${project.basedir}/src/lib</url>
</repository>
</repositories>

<build>
Expand Down Expand Up @@ -68,6 +73,15 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

Expand All @@ -82,16 +96,17 @@
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.semanticweb.elk</groupId>
<artifactId>elk-owlapi-standalone</artifactId>
<version>0.4.1</version>
<classifier>bin</classifier>
</dependency>
<dependency>
<groupId>org.gephi</groupId>
<artifactId>gephi-toolkit</artifactId>
<version>0.8.2</version>
<exclusions>
<exclusion>
<!-- whatever the correct values are -->
<artifactId>google-collections</artifactId>
<groupId>com.google.collections</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>edu.smu.tspell.wordnet</groupId>
Expand All @@ -112,7 +127,7 @@
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-distribution</artifactId>
<version>3.4.10</version>
<version>4.1.3</version>
</dependency>
<dependency>
<groupId>uk.ac.shef.wit</groupId>
Expand All @@ -124,5 +139,35 @@
<artifactId>swingx-all</artifactId>
<version>1.6.4</version>
</dependency>

<!--Pellet Reasoner-->
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>pellet-core-ignazio1977</artifactId>
<version>2.4.0-ignazio1977</version>
</dependency>

<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>pellet-owlapi-ignazio1977</artifactId>
<version>2.4.0-ignazio1977</version>
</dependency>

<dependency>
<groupId>com.github.ansell.aterms</groupId>
<artifactId>aterm-java</artifactId>
<version>1.8.2-p1</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-core</artifactId>
<version>0.9.1</version>
<scope>runtime</scope>
</dependency>


<!-- end Pellet Reasoner-->
</dependencies>
</project>
189 changes: 92 additions & 97 deletions AgreementMakerLight/src/aml/ontology/BKOntology.java
Original file line number Diff line number Diff line change
@@ -1,49 +1,44 @@
/******************************************************************************
* Copyright 2013-2015 LASIGE *
* *
* 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. *
* *
*******************************************************************************
* An Ontology object, loaded using the OWL API. *
* *
* @author Daniel Faria *
* @date 13-08-2015 *
******************************************************************************/
* Copyright 2013-2015 LASIGE *
* *
* 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. *
* *
*******************************************************************************
* An Ontology object, loaded using the OWL API. *
* *
* @author Daniel Faria *
* @date 13-08-2015 *
******************************************************************************/
package aml.ontology;

import java.io.File;
import java.util.Set;

import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAnnotation;
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLLiteral;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;

import aml.settings.LexicalType;
import aml.util.StringParser;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.model.parameters.Imports;
import org.semanticweb.owlapi.search.EntitySearcher;
import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;

import java.io.File;
import java.util.HashSet;
import java.util.Set;

public class BKOntology extends Ontology
{

//Attributes

//Its map of cross-references
protected ReferenceMap refs;


//Constructors

/**
Expand All @@ -54,26 +49,26 @@ public BKOntology()
super();
refs = new ReferenceMap();
}

/**
* Constructs an Ontology from file
* Constructs an Ontology from file
* @param path: the path to the input Ontology file
* @throws OWLOntologyCreationException
* @throws OWLOntologyCreationException
*/
public BKOntology(String path) throws OWLOntologyCreationException
{
this();
//Load the local ontology
File f = new File(path);
OWLOntology o;
//Load the local ontology
File f = new File(path);
OWLOntology o;
o = manager.loadOntologyFromOntologyDocument(f);
uri = f.getAbsolutePath();
init(o);
//Close the OntModel
manager.removeOntology(o);
//Reset the entity expansion limit
System.clearProperty(LIMIT);
//Check if a xrefs file with the same name as the ontology exists
manager.removeOntology(o);
//Reset the entity expansion limit
System.clearProperty(LIMIT);
//Check if a xrefs file with the same name as the ontology exists
String refName = path.substring(0,path.lastIndexOf(".")) + ".xrefs";
f = new File(refName);
if(f.exists())
Expand All @@ -89,35 +84,35 @@ public void close()
super.close();
refs = null;
}

/**
* @return the ReferenceMap of the Ontology
*/
public ReferenceMap getReferenceMap()
{
return refs;
}
//Private Methods

//Private Methods

//Builds the ontology data structures
private void init(OWLOntology o)
{
//Update the URI of the ontology (if it lists one)
if(o.getOntologyID().getOntologyIRI() != null)
uri = o.getOntologyID().getOntologyIRI().toString();
if(o.getOntologyID().getOntologyIRI().isPresent())
uri = o.getOntologyID().getOntologyIRI().get().toString();

//Get the classes and their lexical and cross-reference information
//The internal index of the class
int id = 0;
//The Lexical type and weight
LexicalType type;
double weight;

//The label property
OWLAnnotationProperty label = factory.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI());
//Get an iterator over the ontology classes
Set<OWLClass> owlClasses = o.getClassesInSignature(true);
Set<OWLClass> owlClasses = o.getClassesInSignature(Imports.INCLUDED);
//Then get the URI for each class
for(OWLClass c : owlClasses)
{
Expand All @@ -128,7 +123,7 @@ private void init(OWLOntology o)
classes.add(++id);
//Get the local name from the URI
String name = getLocalName(classUri);

//If the local name is not an alphanumeric code, add it to the lexicon
if(!StringParser.isNumericId(name))
{
Expand All @@ -138,56 +133,56 @@ private void init(OWLOntology o)
}

//Now get the class's annotations (including imports)
Set<OWLAnnotation> annots = c.getAnnotations(o);
Set<OWLAnnotation> annots = new HashSet<>(EntitySearcher.getAnnotations(c, o));
for(OWLOntology ont : o.getImports())
annots.addAll(c.getAnnotations(ont));
for(OWLAnnotation annotation : annots)
{
//Labels and synonyms go to the Lexicon
String propUri = annotation.getProperty().getIRI().toString();
type = LexicalType.getLexicalType(propUri);
if(type != null)
{
weight = type.getDefaultWeight();
if(annotation.getValue() instanceof OWLLiteral)
{
OWLLiteral val = (OWLLiteral) annotation.getValue();
name = val.getLiteral();
String lang = val.getLang();
if(lang.equals(""))
lang = "en";
lex.addClass(id, name, lang, type, "", weight);
}
else if(annotation.getValue() instanceof IRI)
{
OWLNamedIndividual ni = factory.getOWLNamedIndividual((IRI) annotation.getValue());
for(OWLAnnotation a : ni.getAnnotations(o,label))
{
if(a.getValue() instanceof OWLLiteral)
{
OWLLiteral val = (OWLLiteral) a.getValue();
name = val.getLiteral();
String lang = val.getLang();
if(lang.equals(""))
lang = "en";
lex.addClass(id, name, lang, type, "", weight);
}
}
}
}
//xRefs go to the ReferenceMap
else if(propUri.endsWith("hasDbXref") &&
annotation.getValue() instanceof OWLLiteral)
{
OWLLiteral val = (OWLLiteral) annotation.getValue();
annots.addAll(EntitySearcher.getAnnotations(c, ont));
for(OWLAnnotation annotation : annots)
{
//Labels and synonyms go to the Lexicon
String propUri = annotation.getProperty().getIRI().toString();
type = LexicalType.getLexicalType(propUri);
if(type != null)
{
weight = type.getDefaultWeight();
if(annotation.getValue() instanceof OWLLiteral)
{
OWLLiteral val = (OWLLiteral) annotation.getValue();
name = val.getLiteral();
String lang = val.getLang();
if(lang.equals(""))
lang = "en";
lex.addClass(id, name, lang, type, "", weight);
}
else if(annotation.getValue() instanceof IRI)
{
OWLNamedIndividual ni = factory.getOWLNamedIndividual((IRI) annotation.getValue());
for(OWLAnnotation a : EntitySearcher.getAnnotations(ni, o, label))
{
if(a.getValue() instanceof OWLLiteral)
{
OWLLiteral val = (OWLLiteral) a.getValue();
name = val.getLiteral();
String lang = val.getLang();
if(lang.equals(""))
lang = "en";
lex.addClass(id, name, lang, type, "", weight);
}
}
}
}
//xRefs go to the ReferenceMap
else if(propUri.endsWith("hasDbXref") &&
annotation.getValue() instanceof OWLLiteral)
{
OWLLiteral val = (OWLLiteral) annotation.getValue();
String xRef = val.getLiteral();
if(!xRef.startsWith("http"))
refs.add(id,xRef.replace(':','_'));
}
}
}
}
}
}

//Get the local name of an entity from its URI
private String getLocalName(String uri)
{
Expand Down
Loading