Skip to content

Commit

Permalink
Merge pull request #25 from diging/develop
Browse files Browse the repository at this point in the history
prepare releases
  • Loading branch information
jdamerow authored Feb 17, 2022
2 parents 6fc0954 + b5dd924 commit f4deb9b
Show file tree
Hide file tree
Showing 23 changed files with 845 additions and 220 deletions.
2 changes: 1 addition & 1 deletion wic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<apache-tiles.version>3.0.8</apache-tiles.version>
<admin.password>admin</admin.password>

<hibernate.version>5.4.22.Final</hibernate.version>
<hibernate.version>5.4.24.Final</hibernate.version>
<hibernate.dialect>org.hibernate.dialect.MySQL5Dialect</hibernate.dialect>
<hibernate.dialect.storage_engine>InnoDB</hibernate.dialect.storage_engine>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package edu.asu.diging.wic.core.conceptpower;

import java.util.List;

import edu.asu.diging.wic.core.model.IConceptType;

public interface IConceptEntry {

String getConceptId();

String getConceptUri();

String getLemma();

String getPos();

String getDescription();

String getConceptList();

IConceptType getType();

String getCreatorId();

List<String> getEqualTo();

List<String> getSimilarTo();

List<String> getWordnetIds();

<T extends IConceptEntryId> List<T> getAlternativeIds();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package edu.asu.diging.wic.core.conceptpower;

public interface IConceptEntryId {

String getConceptId();

String getConceptUri();

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package edu.asu.diging.wic.core.conceptpower;

import edu.asu.diging.wic.core.conceptpower.impl.ConceptpowerConcept;
import edu.asu.diging.wic.core.model.IConcept;

public interface IConceptMapper {

IConcept mapConceptpowerConceptToConcept(ConceptpowerConcept conceptpowerConcept);

/**
* Maps the Conceptpower entry received to the concept object
* @param conceptEntry received conceptpower entry
* @return the mapped object
*/
IConcept mapConceptpowerConceptToConcept(IConceptEntry conceptEntry);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package edu.asu.diging.wic.core.conceptpower;

import java.util.List;

import edu.asu.diging.wic.core.model.IConcept;
import edu.asu.diging.wic.core.model.impl.ConceptType;

public interface IConceptpowerCache {

IConcept getConceptById(String uri);

IConcept getConceptByUri(String uri);

List<ConceptType> getAllConceptTypes();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package edu.asu.diging.wic.core.conceptpower.db;

import java.util.List;

import edu.asu.diging.wic.core.model.IConcept;
import edu.asu.diging.wic.core.model.IConceptType;
import edu.asu.diging.wic.core.model.impl.ConceptType;

public interface IConceptDatabaseConnection {

Expand All @@ -14,5 +17,6 @@ public interface IConceptDatabaseConnection {
IConceptType getType(String uri);

IConcept getConceptByUri(String uri);


List<ConceptType> getAllConceptTypes();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.TypedQuery;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -31,11 +32,9 @@ public class ConceptDatabaseConnection implements IConceptDatabaseConnection {

@Override
public IConcept getConcept(String id) {

Object objConcept = null;

Query query = em
.createQuery("SELECT c from Concept c WHERE c.id = :id");

Query query = em.createQuery("SELECT c from Concept c WHERE c.id = :id");
query.setParameter("id", id);
List<?> results = query.getResultList();
if (results != null && !results.isEmpty()) {
Expand Down Expand Up @@ -64,8 +63,7 @@ public IConcept getConceptByUri(String uri) {

// let's check if concept uses a different main id
if (objConcept == null) {
Query query = em.createQuery(
"SELECT c from Concept c WHERE :uri in elements(c.alternativeUris)");
Query query = em.createQuery("SELECT c from Concept c WHERE :uri in elements(c.alternativeUris)");
query.setParameter("uri", uri);
List<?> results = query.getResultList();
if (results != null && !results.isEmpty()) {
Expand Down Expand Up @@ -95,19 +93,17 @@ public void createOrUpdate(IConcept concept) {
Object objConcept = em.find(Concept.class, concept.getUri());
// if concept exists, let's update it
if (objConcept == null || isDifferent(concept, (IConcept) objConcept)) {
logger.debug((objConcept == null ? "Adding " : "Updating: ")
+ concept.getUri());
logger.debug((objConcept == null ? "Adding " : "Updating: ") + concept.getUri());
concept.setLastUpdated(OffsetDateTime.now());

if (objConcept != null) {
em.detach(objConcept);
em.remove(objConcept);
}
em.persist(concept);
}

// update type if there is one
if (concept.getTypeId() != null
&& !concept.getTypeId().trim().isEmpty()) {
if (concept.getTypeId() != null && !concept.getTypeId().trim().isEmpty()) {
IConceptType type = getType(concept.getTypeId());
if (type == null || isDifferent(concept.getType(), type)) {
if (type != null) {
Expand All @@ -122,8 +118,7 @@ public void createOrUpdate(IConcept concept) {

@Override
public void deleteConcept(String uri) {
Object concept = em.find(Concept.class,
uri);
Object concept = em.find(Concept.class, uri);
if (concept != null) {
em.remove(concept);
}
Expand All @@ -138,9 +133,14 @@ public IConceptType getType(String id) {
return null;
}

@Override
public List<ConceptType> getAllConceptTypes() {
TypedQuery<ConceptType> query = em.createQuery("from ConceptType", ConceptType.class);
return query.getResultList();
}

private boolean isDifferent(IConcept concept1, IConcept concept2) {
if (concept1.getAlternativeUris().size()
!= concept2.getAlternativeUris().size()) {
if (concept1.getAlternativeUris().size() != concept2.getAlternativeUris().size()) {
return true;
}
List<String> altIds1 = new ArrayList<>(concept1.getAlternativeUris());
Expand All @@ -156,10 +156,10 @@ private boolean isDifferent(IConcept concept1, IConcept concept2) {
if (!concept1.getDescription().equals(concept2.getDescription())) {
return true;
}
if (concept1.getEqualTo().size() !=concept2.getEqualTo().size()) {
if (concept1.getEqualTo().size() != concept2.getEqualTo().size()) {
return true;
}

List<String> equalTo1 = new ArrayList<>(concept1.getEqualTo());
List<String> equalTo2 = new ArrayList<>(concept2.getEqualTo());
Collections.sort(equalTo1);
Expand All @@ -182,7 +182,7 @@ private boolean isDifferent(IConcept concept1, IConcept concept2) {
if (!concept1.getWord().equals(concept2.getWord())) {
return true;
}
if (concept1.getWordnetIds().size() !=concept2.getWordnetIds().size()) {
if (concept1.getWordnetIds().size() != concept2.getWordnetIds().size()) {
return true;
}
List<String> wordnetIds1 = new ArrayList<>(concept1.getWordnetIds());
Expand Down Expand Up @@ -216,4 +216,5 @@ private boolean isDifferent(IConceptType type1, IConceptType type2) {
}
return false;
}
}

}
Loading

0 comments on commit f4deb9b

Please sign in to comment.