├── .gitignore ├── PraxiconXMLTags.html ├── README.md ├── catalog.xml ├── docs ├── Praxicon_database_documentation_20160706.pdf └── Praxicon_database_tutorial_20160919.pdf ├── misc ├── checkstyle.xml ├── exports │ └── ConceptsSample.xml ├── formatting.zip ├── netbeans_styling.zip ├── settings.properties.sample └── test-fixtures │ ├── Concepts.xml │ ├── ConceptsSample.xml │ ├── Concepts_colour_abstract_20160712172921.xml │ ├── Objects.xml │ ├── RelationSets.xml │ └── Relations.xml ├── pom.xml ├── src ├── main │ ├── gr │ │ └── csri │ │ │ └── poeticon │ │ │ └── praxicon │ │ │ ├── Constants.java │ │ │ ├── CreateNeo4JDB.java │ │ │ ├── CreateNewBLRelations.java │ │ │ ├── EntityMngFactory.java │ │ │ ├── GeneratePraxiconXSD.java │ │ │ ├── Globals.java │ │ │ ├── ImageAnalysisResult.java │ │ │ ├── PraxiconDBOutputResolver.java │ │ │ ├── SimpleTest.java │ │ │ ├── TestJPA.java │ │ │ ├── Utils.java │ │ │ ├── XmlUtils.java │ │ │ └── db │ │ │ ├── dao │ │ │ ├── ConceptDao.java │ │ │ ├── Concept_LanguageRepresentationDao.java │ │ │ ├── Dao.java │ │ │ ├── LanguageRepresentationDao.java │ │ │ ├── MotoricRepresentationDao.java │ │ │ ├── RelationArgumentDao.java │ │ │ ├── RelationDao.java │ │ │ ├── RelationSetDao.java │ │ │ ├── RelationTypeDao.java │ │ │ ├── VisualRepresentationDao.java │ │ │ ├── implSQL │ │ │ │ ├── ConceptDaoImpl.java │ │ │ │ ├── Concept_LanguageRepresentationDaoImpl.java │ │ │ │ ├── JpaDao.java │ │ │ │ ├── LanguageRepresentationDaoImpl.java │ │ │ │ ├── MotoricRepresentationDaoImpl.java │ │ │ │ ├── RelationArgumentDaoImpl.java │ │ │ │ ├── RelationDaoImpl.java │ │ │ │ ├── RelationSetDaoImpl.java │ │ │ │ ├── RelationTypeDaoImpl.java │ │ │ │ └── VisualRepresentationDaoImpl.java │ │ │ └── implXML │ │ │ │ ├── LanguageRepresentationDaoImplXML.java │ │ │ │ ├── MotoricRepresentationDaoImplXML.java │ │ │ │ ├── RelationSetDaoImplXML.java │ │ │ │ └── VisualRepresentationDaoImplXML.java │ │ │ └── entities │ │ │ ├── CollectionOfObjects.java │ │ │ ├── Concept.java │ │ │ ├── Concept_LanguageRepresentation.java │ │ │ ├── Concepts.java │ │ │ ├── ConstraintValidator.java │ │ │ ├── LanguageRepresentation.java │ │ │ ├── MotoricRepresentation.java │ │ │ ├── OntologicalDomain.java │ │ │ ├── Relation.java │ │ │ ├── RelationArgument.java │ │ │ ├── RelationArguments.java │ │ │ ├── RelationSet.java │ │ │ ├── RelationSet_Relation.java │ │ │ ├── RelationSets.java │ │ │ ├── RelationType.java │ │ │ ├── Relations.java │ │ │ ├── VisualRepresentation.java │ │ │ ├── comparators │ │ │ ├── LexicalEntryComparator.java │ │ │ ├── MotoricEntryComparator.java │ │ │ └── VisualEntryComparator.java │ │ │ ├── jaxb.index │ │ │ ├── listeners │ │ │ └── ConceptListener.java │ │ │ ├── package-info.java │ │ │ └── validators │ │ │ ├── ConceptValidator.java │ │ │ └── ConstantConcepts.java │ └── resources │ │ └── META-INF │ │ └── persistence.xml.sample └── test │ ├── gr │ └── csri │ │ └── poeticon │ │ └── praxicon │ │ └── db │ │ └── dao │ │ └── implSQL │ │ └── ConceptDaoImplTest.java │ ├── java │ └── gr │ │ └── csri │ │ └── poeticon │ │ └── praxicon │ │ └── db │ │ ├── dao │ │ └── implSQL │ │ │ └── ConceptDaoImplTest.java │ │ └── entities │ │ └── ConceptTest.java │ └── resources │ └── META-INF │ └── persistence.xml ├── templates ├── jaxb.xdt └── xmlHelpFile.xdt └── xsd ├── compositionality.xsd ├── concept.xsd ├── constituent.xsd ├── intersection_of_relation_chains.xsd ├── language_representation.xsd ├── motoric_representation.xsd ├── relation.xsd ├── relation_chain.xsd ├── relation_type.xsd ├── relationchain_relation.xsd ├── verbalization.xsd └── visual_representation.xsd /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Package Files # 4 | *.jar 5 | *.war 6 | *.ear 7 | /dist/ 8 | /build/ 9 | /schema1.xsd 10 | /schema4.xsd 11 | /schema3.xsd 12 | /schema10.xsd 13 | /schema5.xsd 14 | /schema11.xsd 15 | /schema2.xsd 16 | /schema7.xsd 17 | /schema6.xsd 18 | /schema9.xsd 19 | /schema8.xsd 20 | /schema12.xsd 21 | /xsd/ 22 | /target/ -------------------------------------------------------------------------------- /PraxiconXMLTags.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Praxicon's XML Tags Index 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 |
Praxicon's XML Tags Index
nameThis attribute defines the name of the element
<language_representation>This tag defines the Language Representation of the concept
<visual_representation>This tag defines the Visual Representation of the concept
<relation_chain>This tag defines a relation
colorThis attribute defines if the Entity Feature represents a color
sizeThis attribute defines if the Entity Feature represents some size
shapeThis attribute defines if the Entity Feature represents a shape
textureThis attribute defines if the Entity Feature represents a texture
weightThis attribute defines if the Entity Feature represents weight
order
prototype
<media_type>
<motoric_representation>This tag defines the motoric representation
<language>This tag defines the language of the entry
<text>This tag defines the text of the entry
objThis attribute defines the object that the relation is related to
<type>This tag defines the type of the relation
accelarationThis attribute defines if the Movement Feature represents an accelaration
body_part_actuatorThis attribute defines if the Movement Feature represents a body part actuator
direction_of_motionThis attribute defines if the Movement Feature represents the direction of motion
speed_rateThis attribute defines if the Movement Feature represents some speed rate
velocityThis attribute defines if the Movement Feature represents some velocity
<representation>This tag defines the (visual or motoric) representation of the entity as a path to a file
<relation>
<left-to-right_name>The name of the relation when the relational triplet is used from left to right
<left-to-right_name>The name of the relation when the relational triplet is used from left to right
<intersection_of_relation_chains>This tag defines the intersections of some relations
121 | 122 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PraxiconDB 2 | ========== 3 | The PRAXICON is a conceptual knowledge base in which concepts have both symbolic 4 | (e.g. natural language) and corresponding sensorimotor representations, while 5 | associations among them are pragmatic in nature and recursive. The resource has 6 | been developed to allow artificial agents/systems: 7 | - to tie concepts/words of different levels of abstraction to their 8 | sensorimotor instantiations (catering thus for disambiguation), and 9 | - to untie sensorimotor representations from their physical specificities 10 | correlating them to conceptual structures of different levels of abstraction 11 | (catering thus for intentionality indication). 12 | 13 | The PRAXICON database is a 3rd normal form database that stores information on 14 | embodied concepts. The design of the database ensures that any application that 15 | uses the PRAXICON knowledge base and its tools will have easy access to the 16 | stored data, with minimum overhead. To this end, we have included some features 17 | that are not currently used by the POETICON project applications, but will be 18 | useful for future extensions of the PRAXICON and use in different applications 19 | (e.g. in machine translation). 20 | 21 | Description 22 | ----------- 23 | The core entity of the database is the Concept table. It connects concepts/words 24 | of different levels of abstraction to their sensorimotor and visual 25 | instantiations. Each concept has a linguistic representation and can 26 | optionally have a motoric and/or a visual representation. 27 | 28 | Each Concept can be member of one or more Relations. Relations usually comprise 29 | of a triplet having the following form: "Concept A – Relation – Concept B". 30 | This means that Concept A (left relation argument) is related with some 31 | Relation to Concept B. These Relations are always bidirectional, so the 32 | aforementioned triplet also stands for Concept B is related (with the reverse 33 | relation) with Concept A. These triplets are the simplest form of a Relation. 34 | 35 | This simple form of a Relation cannot by itself express the perplexity of 36 | the world we live in. We need to be able to combine simple Relations into more 37 | complex structures. These are called Relation Sets. A Relation Set can contain 38 | one or more Relations bundled together as one entity. 39 | 40 | In addition, a Relation Set can be at the left or right side of a Relation, thus 41 | creating a recursive schema. More details on how Relations interact with 42 | Relation Sets and Concepts can be found in the documentation. 43 | 44 | Getting the Software 45 | -------------------- 46 | There are two ways to get the PraxiconDB: 47 | 48 | 1. Get the latest stable release from https://github.com/CSRI/PraxiconDB/tags. 49 | 50 | 2. Get the latest development version by creating a local fork of the project 51 | on your Git account and clone it locally (https://github.com/CSRI/PraxiconDB.git). 52 | 53 | Installation and Usage 54 | ---------------------- 55 | For installation and usage instructions please refer to the documentation 56 | in the manuals under `docs/`. 57 | 58 | Reporting Issues 59 | ---------------- 60 | If you spot any bugs, please report them to the GitHub's issue tracker: 61 | https://github.com/CSRI/PraxiconDB/issues. 62 | 63 | Development 64 | ----------- 65 | If you would like to contribute to the project, just fork it, and send 66 | pull requests with your changes. If you require assistance, please 67 | contact the authors. 68 | -------------------------------------------------------------------------------- /catalog.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /docs/Praxicon_database_documentation_20160706.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CSRI/PraxiconDB/2b8b264aa16658820c457a9f34ab63d6f446144b/docs/Praxicon_database_documentation_20160706.pdf -------------------------------------------------------------------------------- /docs/Praxicon_database_tutorial_20160919.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CSRI/PraxiconDB/2b8b264aa16658820c457a9f34ab63d6f446144b/docs/Praxicon_database_tutorial_20160919.pdf -------------------------------------------------------------------------------- /misc/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /misc/formatting.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CSRI/PraxiconDB/2b8b264aa16658820c457a9f34ab63d6f446144b/misc/formatting.zip -------------------------------------------------------------------------------- /misc/netbeans_styling.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CSRI/PraxiconDB/2b8b264aa16658820c457a9f34ab63d6f446144b/misc/netbeans_styling.zip -------------------------------------------------------------------------------- /misc/settings.properties.sample: -------------------------------------------------------------------------------- 1 | # Database settings (for now you should use mysql db) 2 | # URL of the db server (default:localhost) 3 | db.host= 4 | # Port the db server listens to (default:3306) 5 | db.port= 6 | # Name of the database (default:praxicon) 7 | db.name= 8 | # Username of db user 9 | db.username= 10 | # Password of user 11 | db.password= 12 | 13 | 14 | # Some paths 15 | # A temporary path to mainly store XML files 16 | path.tmp= 17 | # Images reside here 18 | path.images= 19 | # ImageNet images reside here 20 | path.imageNet= 21 | # LabelMe images reside here 22 | path.labelMe= 23 | # Videos reside here 24 | path.videos= 25 | # Sounds reside here 26 | path.sounds= 27 | 28 | # Some URLs 29 | # LabelMe URL 30 | url.labelMe= 31 | # LabelMe images URL 32 | url.labelMeImages= 33 | # ImageNet URL 34 | url.imageNet= 35 | 36 | # Some constants 37 | # Weight for variable solver 38 | const.variableSolverWeight= 39 | 40 | -------------------------------------------------------------------------------- /misc/test-fixtures/Concepts_colour_abstract_20160712172921.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 104674968 5 | color%1:07:01:: 6 | UNKNOWN 7 | SUPERORDINATE 8 | CONSTANT 9 | ABSTRACT 10 | NO 11 | WordNet3.0 12 | 13 | 14 | false 15 | 16 | EN 17 | LITERAL 18 | NOUN 19 | color 20 | 21 | 22 | 23 | false 24 | 25 | EN 26 | LITERAL 27 | NOUN 28 | colour 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /misc/test-fixtures/RelationSets.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 21074 7 | 8 | ACTION_GOAL 9 | GOAL_ACTION 10 | 11 | 12 | 13 | brooch%2:35:00::#with#brooch%1:06:00::#the#dummy_object_brooch%2:35:00::_brooch%1:06:00:: 14 | MOVEMENT 15 | SUBORDINATE 16 | VARIABLE 17 | UNKNOWN 18 | NO 19 | WordNet3.0 20 | 21 | 22 | 23 | 24 | 25 | 201548576 26 | brooch%2:35:00:: 27 | MOVEMENT 28 | SUBORDINATE 29 | CONSTANT 30 | UNKNOWN 31 | NO 32 | WordNet3.0 33 | 34 | 35 | false 36 | 37 | EN 38 | UNKNOWN 39 | VERB 40 | brooch 41 | 42 | 43 | 44 | false 45 | 46 | EN 47 | UNKNOWN 48 | VERB 49 | clasp 50 | 51 | 52 | 53 | 54 | NO 55 | 56 | 57 | 58 | 59 | 21075 60 | 61 | ACTION_TOOL 62 | TOOL_ACTION 63 | 64 | 65 | 66 | brooch%2:35:00::#with#brooch%1:06:00::#the#dummy_object_brooch%2:35:00::_brooch%1:06:00:: 67 | MOVEMENT 68 | SUBORDINATE 69 | VARIABLE 70 | UNKNOWN 71 | NO 72 | WordNet3.0 73 | 74 | 75 | 76 | 77 | 78 | 102906438 79 | brooch%1:06:00:: 80 | ENTITY 81 | SUBORDINATE 82 | CONSTANT 83 | UNKNOWN 84 | NO 85 | WordNet3.0 86 | 87 | 88 | false 89 | 90 | EN 91 | LITERAL 92 | NOUN 93 | breastpin 94 | 95 | 96 | 97 | false 98 | 99 | EN 100 | LITERAL 101 | NOUN 102 | broach 103 | 104 | 105 | 106 | false 107 | 108 | EN 109 | LITERAL 110 | NOUN 111 | brooch 112 | 113 | 114 | 115 | 116 | YES 117 | 118 | 119 | 120 | 121 | 21076 122 | 123 | ACTION_OBJECT 124 | OBJECT_ACTION 125 | 126 | 127 | 128 | brooch%2:35:00::#with#brooch%1:06:00::#the#dummy_object_brooch%2:35:00::_brooch%1:06:00:: 129 | MOVEMENT 130 | SUBORDINATE 131 | VARIABLE 132 | UNKNOWN 133 | NO 134 | WordNet3.0 135 | 136 | 137 | 138 | 139 | 140 | dummy_object_brooch%2:35:00::_brooch%1:06:00:: 141 | ENTITY 142 | UNKNOWN 143 | VARIABLE 144 | UNKNOWN 145 | UNKNOWN 146 | WordNet3.0 147 | 148 | 149 | 150 | UNKNOWN 151 | 152 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/Constants.java: -------------------------------------------------------------------------------- 1 | package gr.csri.poeticon.praxicon; 2 | 3 | import gr.csri.poeticon.praxicon.db.entities.Concept; 4 | import gr.csri.poeticon.praxicon.db.entities.Concepts; 5 | import java.io.FileInputStream; 6 | import java.io.FileNotFoundException; 7 | import java.io.IOException; 8 | import java.util.Hashtable; 9 | import java.util.Properties; 10 | 11 | /** 12 | * All the constants and globals of the project. All properties taken from 13 | * "settings.properties" file. 14 | * 15 | * @author Dimitris Mavroeidis 16 | * @date 18/09/2013 17 | * 18 | */ 19 | public class Constants { 20 | 21 | // DB settings constants 22 | public static String dbHost; 23 | public static String dbPort; 24 | public static String dbName; 25 | public static String dbUser; 26 | public static String dbPass; 27 | 28 | // Path constants 29 | /** 30 | * The temporary path 31 | */ 32 | public static String tmpPath; 33 | 34 | /** 35 | * The path to the image resources 36 | */ 37 | public static String imagePath; 38 | 39 | /** 40 | * The path to the LabelMe image resources 41 | */ 42 | public static String imagePathLabelMe; 43 | 44 | /** 45 | * The path to the ImageNet image resources 46 | */ 47 | public static String imagePathImageNet; 48 | 49 | /** 50 | * The path to the video resources 51 | */ 52 | public static String videoPath; 53 | 54 | /** 55 | * * The path to the sound resources 56 | */ 57 | public static String soundPath; 58 | 59 | // URL constants 60 | /** 61 | * The URL string to labelMe 62 | */ 63 | public static String LabelMeURL; 64 | 65 | /** 66 | * The URL string to labelMe actual images 67 | */ 68 | public static String LabelMeImagesURL; 69 | 70 | /** 71 | * The URL string to ImageNet 72 | */ 73 | public static String ImageNetURL; 74 | 75 | // Other constants 76 | /** 77 | * A weight that it is being used by the variable solver (the weight of an 78 | * inherent relation) 79 | */ 80 | public static double weightForVariableSolver; 81 | 82 | /** 83 | * This is used by the similarity functions, to store which objects we have 84 | * already visited 85 | */ 86 | public static Hashtable conceptsVisited = new Hashtable(); 87 | 88 | /** 89 | * A global variable that contains all the concepts that have been loaded 90 | * from an xml. It is used in the XML mode (where we do not have any db) 91 | */ 92 | public static Hashtable globalConcepts = new Hashtable(); 93 | public static Hashtable globalRelations = new Hashtable(); 94 | public static Hashtable globalRelationSets = new Hashtable(); 95 | 96 | /** 97 | * A global variable that contains all the concepts that have been loaded 98 | * from Wordnet. It is used in the Wordnet mode (where we do not have any 99 | * db) 100 | */ 101 | public static Concepts wordNetConcepts; 102 | 103 | public static void Constants() throws FileNotFoundException, IOException { 104 | 105 | Properties props = new Properties(); 106 | FileInputStream fis = new FileInputStream("misc/settings.properties"); 107 | props.load(fis); 108 | 109 | /** 110 | * Get settings. 111 | */ 112 | dbHost = props.getProperty("db.host"); 113 | System.out.println(dbHost); 114 | dbPort = props.getProperty("db.port"); 115 | System.out.println(dbPort); 116 | dbName = props.getProperty("db.name"); 117 | System.out.println(dbName); 118 | dbUser = props.getProperty("db.username"); 119 | System.out.println(dbUser); 120 | dbPass = props.getProperty("db.password"); 121 | System.out.println(dbPass); 122 | tmpPath = props.getProperty("path.tmp"); 123 | imagePath = props.getProperty("path.images"); 124 | imagePathLabelMe = props.getProperty("path.labelMe"); 125 | imagePathImageNet = props.getProperty("path.imageNet"); 126 | videoPath = props.getProperty("path.videos"); 127 | soundPath = props.getProperty("path.sounds"); 128 | LabelMeURL = props.getProperty("url.labelMe"); 129 | LabelMeImagesURL = props.getProperty("url.labelMeImages"); 130 | ImageNetURL = props.getProperty("url.imageNet"); 131 | 132 | weightForVariableSolver = Double.parseDouble(props.getProperty( 133 | "const.variableSolverWeight")); 134 | System.out.println(weightForVariableSolver); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/EntityMngFactory.java: -------------------------------------------------------------------------------- 1 | package gr.csri.poeticon.praxicon; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import javax.persistence.EntityManager; 6 | import javax.persistence.EntityManagerFactory; 7 | 8 | /** 9 | * 10 | * @author dmavroeidis 11 | * 12 | * This class administrates everything that has to do with the Entity Manager 13 | */ 14 | public class EntityMngFactory { 15 | 16 | /** 17 | * The entity Manager Factory 18 | */ 19 | private static EntityManagerFactory emf = null; 20 | 21 | /** 22 | * The Entity Manager 23 | */ 24 | private static EntityManager em = null; 25 | 26 | private static void createEntityMngFactory() { 27 | /* 28 | * Check the environment (testing or production) and choose 29 | * the appropriate persistence unit. 30 | */ 31 | String persistenceUnit; 32 | if (inUnitTest()) { 33 | persistenceUnit = Globals.JpaPUDerbyTest; 34 | } else { 35 | persistenceUnit = Globals.JpaPU; 36 | } 37 | 38 | emf = javax.persistence.Persistence.createEntityManagerFactory( 39 | persistenceUnit); 40 | em = emf.createEntityManager(); 41 | } 42 | 43 | /** 44 | * The constructor 45 | */ 46 | private EntityMngFactory() { 47 | createEntityMngFactory(); 48 | } 49 | 50 | /** 51 | * It was used by the singleton pattern, but we didn't use this pattern 52 | * after all 53 | */ 54 | public static void restart() { 55 | createEntityMngFactory(); 56 | } 57 | 58 | public static EntityManager getEntityManager() { 59 | if (em == null || !em.isOpen()) { 60 | createEntityMngFactory(); 61 | } 62 | return em; 63 | } 64 | 65 | /** 66 | * It closes the Entity Manager 67 | */ 68 | public static void close() { 69 | em.close(); 70 | // em = null; 71 | } 72 | 73 | public static boolean inUnitTest() { 74 | /* 75 | * Addopted from http://stackoverflow.com/questions/2341943/ 76 | * how-can-i-find-out-if-code-is-running-inside-a-junit-test-or-not 77 | */ 78 | StackTraceElement[] stackTrace = Thread.currentThread(). 79 | getStackTrace(); 80 | List list = Arrays.asList(stackTrace); 81 | for (StackTraceElement element : list) { 82 | if (element.getClassName().startsWith("org.junit.")) { 83 | return true; 84 | } 85 | } 86 | return false; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/GeneratePraxiconXSD.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package gr.csri.poeticon.praxicon; 7 | 8 | import gr.csri.poeticon.praxicon.db.entities.CollectionOfObjects; 9 | import gr.csri.poeticon.praxicon.db.entities.Concept; 10 | import gr.csri.poeticon.praxicon.db.entities.Relation; 11 | import gr.csri.poeticon.praxicon.db.entities.RelationSet; 12 | import java.io.IOException; 13 | import javax.xml.bind.JAXBContext; 14 | import javax.xml.bind.JAXBException; 15 | import javax.xml.bind.SchemaOutputResolver; 16 | 17 | /** 18 | * 19 | * @author dmavroeidis 20 | */ 21 | public class GeneratePraxiconXSD { 22 | 23 | public static SchemaOutputResolver scoure; 24 | JAXBContext jaxbContextConcept; 25 | JAXBContext jaxbContextRelation; 26 | JAXBContext jaxbContextRelationSet; 27 | JAXBContext jaxbContextCollectionOfObjects; 28 | 29 | public GeneratePraxiconXSD() throws JAXBException { 30 | this.jaxbContextConcept = JAXBContext.newInstance(Concept.class); 31 | this.jaxbContextRelation = JAXBContext.newInstance(Relation.class); 32 | this.jaxbContextRelationSet = JAXBContext.newInstance( 33 | RelationSet.class); 34 | this.jaxbContextCollectionOfObjects = JAXBContext.newInstance( 35 | CollectionOfObjects.class); 36 | 37 | } 38 | 39 | public static void main(String args[]) throws JAXBException, IOException { 40 | SchemaOutputResolver sour; 41 | JAXBContext jaxbContextConcept; 42 | JAXBContext jaxbContextRelation; 43 | JAXBContext jaxbContextRelationSet; 44 | JAXBContext jaxbContextCollectionOfObjects; 45 | sour = new PraxiconDBOutputResolver(); 46 | jaxbContextConcept = JAXBContext.newInstance(Concept.class); 47 | jaxbContextRelation = JAXBContext.newInstance(Relation.class); 48 | jaxbContextRelationSet = JAXBContext.newInstance(RelationSet.class); 49 | jaxbContextCollectionOfObjects = JAXBContext.newInstance( 50 | CollectionOfObjects.class); 51 | jaxbContextConcept.generateSchema(sour); 52 | jaxbContextRelation.generateSchema(sour); 53 | jaxbContextRelationSet.generateSchema(sour); 54 | jaxbContextCollectionOfObjects.generateSchema(sour); 55 | sour.createOutput("http://www.csri.gr/concept", "misc/xsd/Concept.xsd"); 56 | sour.createOutput("http://www.csri.gr/relation", "misc/xsd/Relation.xsd"); 57 | sour.createOutput("http://www.csri.gr/relationSet", 58 | "misc/xsd/RelationSet.xsd"); 59 | sour.createOutput("http://www.csri.gr/collectionOfObjects", 60 | "misc/xsd/CollectionOfObjects.xsd"); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/Globals.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon; 6 | //import csri.poeticon.praxicon.Constants; 7 | 8 | /** 9 | * 10 | * @author dmavroeidis 11 | * 12 | * All the globals of the project 13 | */ 14 | public class Globals { 15 | 16 | /** 17 | * The JPA persistence unit name 18 | */ 19 | public static String JpaPU = "PraxiconDBPU"; 20 | public static String JpaPUDerbyTest = "PraxiconDBPUDerbyTest"; 21 | 22 | /** 23 | * Flag to mark if the objects that have been loaded from an xml are going 24 | * to be added in the database or they will be used just for browsing 25 | */ 26 | public static boolean ToMergeAfterUnMarshalling = false; 27 | } 28 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/ImageAnalysisResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package gr.csri.poeticon.praxicon; 7 | 8 | /** 9 | * 10 | * @author dmavroeidis 11 | */ 12 | public class ImageAnalysisResult { 13 | 14 | boolean image; 15 | boolean truncated; 16 | 17 | public void setImage(boolean image) { 18 | this.image = image; 19 | } 20 | 21 | public void setTruncated(boolean truncated) { 22 | this.truncated = truncated; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/PraxiconDBOutputResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package gr.csri.poeticon.praxicon; 7 | 8 | import java.io.File; 9 | import java.io.IOException; 10 | import javax.xml.bind.SchemaOutputResolver; 11 | import javax.xml.transform.Result; 12 | import javax.xml.transform.stream.StreamResult; 13 | 14 | /** 15 | * 16 | * @author dmavroeidis 17 | */ 18 | public class PraxiconDBOutputResolver extends SchemaOutputResolver { 19 | 20 | @Override 21 | public Result createOutput(String namespaceURI, String suggestedFileName) 22 | throws IOException { 23 | File file = new File(suggestedFileName); 24 | StreamResult result = new StreamResult(file); 25 | result.setSystemId(file.toURI().toURL().toString()); 26 | return result; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package gr.csri.poeticon.praxicon; 7 | 8 | import gr.csri.poeticon.praxicon.db.dao.ConceptDao; 9 | import gr.csri.poeticon.praxicon.db.dao.VisualRepresentationDao; 10 | import gr.csri.poeticon.praxicon.db.dao.implSQL.ConceptDaoImpl; 11 | import gr.csri.poeticon.praxicon.db.dao.implSQL.VisualRepresentationDaoImpl; 12 | import gr.csri.poeticon.praxicon.db.entities.Concept; 13 | import gr.csri.poeticon.praxicon.db.entities.VisualRepresentation; 14 | import java.awt.image.BufferedImage; 15 | import java.io.BufferedReader; 16 | import java.io.EOFException; 17 | import java.io.FileReader; 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | import java.net.SocketException; 21 | import java.net.SocketTimeoutException; 22 | import java.net.URISyntaxException; 23 | import java.net.URL; 24 | import java.net.URLConnection; 25 | import java.nio.file.FileAlreadyExistsException; 26 | import java.nio.file.Files; 27 | import java.nio.file.NoSuchFileException; 28 | import java.nio.file.Path; 29 | import java.nio.file.Paths; 30 | import java.security.NoSuchAlgorithmException; 31 | import java.util.Iterator; 32 | import javax.imageio.IIOException; 33 | import javax.imageio.ImageIO; 34 | import javax.imageio.ImageReader; 35 | import javax.imageio.stream.ImageInputStream; 36 | import javax.swing.ImageIcon; 37 | 38 | /** 39 | * 40 | * @author dmavroeidis 41 | */ 42 | public class Utils { 43 | 44 | public enum FileExtensions { 45 | 46 | jpeg, tiff, jpg, jpe, gif, tif, bmp 47 | } 48 | 49 | public static void main(String args[]) throws IOException, 50 | URISyntaxException, NoSuchAlgorithmException { 51 | importPhotosFromImagenet("/home/dmavroeidis/Desktop/ImageNet/"); 52 | System.exit(0); 53 | } 54 | 55 | public static void importPhotosFromImagenet(String savePath) throws 56 | IOException, URISyntaxException, NoSuchAlgorithmException { 57 | /* 58 | * 1. Read file with image URLs 59 | * 2. For each line, 60 | * 2.1. Get the first column as the sysnset 61 | * 2.1.1. Replace the first digit from n to 1. 62 | * 2.1.2. Cut all the part from the last underscore. 63 | * 2.1.3. Save this as the sysnset ID. 64 | * 2.2. Get the second column as the URL 65 | * 2.3. Find the Concept according to the sysnset ID (externalSourceId) 66 | * 2.4. Add the Visual Representation with the following fields: 67 | * 2.4.1. MediaType = IMAGE 68 | * 2.4.2. Source = ImageNet_fall_2011 69 | * 2.4.3. Uri = URL 70 | * 2.4.4. Name = first column 71 | */ 72 | 73 | ConceptDao cDao = new ConceptDaoImpl(); 74 | Concept concept = new Concept(); 75 | boolean corrupted = false; 76 | VisualRepresentationDao vrDao = new VisualRepresentationDaoImpl(); 77 | 78 | try (BufferedReader br = new BufferedReader(new FileReader( 79 | "/home/dmavroeidis/Desktop/fall11_urls.txt"))) { 80 | String line; 81 | while ((line = br.readLine()) != null) { 82 | String[] columnDetail = new String[2]; 83 | columnDetail = line.split("\t", -1); 84 | String url = columnDetail[1]; 85 | String imageNetId = columnDetail[0]; 86 | String synsetId = imageNetId.replace("n", "1").substring(0, 9); 87 | concept = cDao.getConceptByExternalSourceIdExact(synsetId); 88 | corrupted = false; 89 | // Only get the first 5 entries of BASIC_LEVEL and-below concepts 90 | if ((concept.getVisualRepresentationsEntries().size() < 5) && 91 | (concept.getSpecificityLevel() != 92 | Concept.SpecificityLevel.SUPERORDINATE)) { 93 | 94 | // Check if file is an image 95 | URL imageUrl = new URL(url); 96 | URLConnection conn = imageUrl.openConnection(); 97 | conn.setConnectTimeout(3000); 98 | conn.setReadTimeout(3000); 99 | InputStream in = null; //Initialize input stream 100 | try { 101 | in = conn.getInputStream(); 102 | } catch (IOException | IllegalArgumentException ioE) { 103 | continue; 104 | } 105 | 106 | int beginIndex = url.lastIndexOf(".") + 1; 107 | String saveFile; 108 | String imageExtension; 109 | 110 | imageExtension = url.substring(beginIndex).toLowerCase(); 111 | 112 | if (imageExtension.startsWith(FileExtensions.jpeg. 113 | toString()) || 114 | imageExtension.startsWith( 115 | FileExtensions.tiff.toString())) { 116 | saveFile = savePath + imageNetId + "." + 117 | imageExtension.substring(0, 4); 118 | } else if (imageExtension. 119 | startsWith(FileExtensions.gif.toString()) || 120 | imageExtension.startsWith(FileExtensions.jpg. 121 | toString()) || 122 | imageExtension.startsWith(FileExtensions.tif. 123 | toString()) || 124 | imageExtension.startsWith(FileExtensions.jpe. 125 | toString()) || 126 | imageExtension.startsWith(FileExtensions.bmp. 127 | toString())) { 128 | saveFile = savePath + imageNetId + "." + 129 | imageExtension.substring(0, 3); 130 | } else { 131 | saveFile = savePath + imageNetId + "." + "jpg"; 132 | } 133 | 134 | System.out.println("FILE: " + saveFile + "\tURL: " + url); 135 | 136 | // Copy the image from the web. 137 | try { 138 | Files.copy(in, Paths.get(saveFile)); 139 | } catch (FileAlreadyExistsException | NoSuchFileException | 140 | SocketTimeoutException | SocketException faeE) { 141 | continue; 142 | } 143 | 144 | // Check the validity of the image. 145 | ImageAnalysisResult iaResult = new ImageAnalysisResult(); 146 | try { 147 | iaResult = analyzeImage(Paths.get(saveFile)); 148 | } catch (IllegalArgumentException iaE) { 149 | corrupted = true; 150 | } 151 | if (iaResult.truncated) { 152 | corrupted = true; 153 | } 154 | 155 | // Check size of the image. 156 | ImageIcon img = new ImageIcon(saveFile); 157 | int imageWidth = img.getIconWidth(); 158 | int imageHeight = img.getIconHeight(); 159 | if (imageWidth < 201 || imageHeight < 201) { 160 | corrupted = true; 161 | } 162 | 163 | // Delete the image if it does not comply with standards. 164 | if (corrupted) { 165 | Files.delete(Paths.get(saveFile)); 166 | continue; 167 | } 168 | 169 | VisualRepresentation vr = new VisualRepresentation( 170 | VisualRepresentation.MediaType.IMAGE, imageNetId); 171 | vr.setUri(url); 172 | vr.setConcept(concept); 173 | vr.setSource("ImageNet_fall_2011"); 174 | vrDao.merge(vr); 175 | cDao.clearManager(); 176 | } 177 | } 178 | } 179 | } 180 | 181 | /** 182 | * Analyze the image, checking if it is truncated or not. 183 | * 184 | * @param file - The path to the image file 185 | * 186 | * @return whether the image is truncated or not 187 | * 188 | * @throws NoSuchAlgorithmException 189 | * @throws IOException 190 | */ 191 | public static ImageAnalysisResult analyzeImage(final Path file) 192 | throws NoSuchAlgorithmException, IOException { 193 | final ImageAnalysisResult result = new ImageAnalysisResult(); 194 | try (InputStream digestInputStream = Files.newInputStream(file)) { 195 | final ImageInputStream imageInputStream = ImageIO 196 | .createImageInputStream(digestInputStream); 197 | final Iterator imageReaders = ImageIO 198 | .getImageReaders(imageInputStream); 199 | if (!imageReaders.hasNext()) { 200 | result.setImage(false); 201 | return result; 202 | } 203 | final ImageReader imageReader = imageReaders.next(); 204 | imageReader.setInput(imageInputStream); 205 | final BufferedImage image = imageReader.read(0); 206 | if (image == null) { 207 | return result; 208 | } 209 | image.flush(); 210 | if (imageReader.getFormatName().equals("JPEG")) { 211 | imageInputStream. 212 | seek(imageInputStream.getStreamPosition() - 2); 213 | final byte[] lastTwoBytes = new byte[2]; 214 | imageInputStream.read(lastTwoBytes); 215 | if (lastTwoBytes[0] != (byte)0xff || lastTwoBytes[1] != 216 | (byte)0xd9) { 217 | result.setTruncated(true); 218 | } else { 219 | result.setTruncated(false); 220 | } 221 | } 222 | result.setImage(true); 223 | } catch (final IndexOutOfBoundsException e) { 224 | result.setTruncated(true); 225 | } catch (final IIOException e) { 226 | if (e.getCause() instanceof EOFException) { 227 | result.setTruncated(true); 228 | } 229 | } 230 | return result; 231 | } 232 | } 233 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/ConceptDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao; 6 | 7 | import gr.csri.poeticon.praxicon.db.dao.implSQL.ConceptDaoImpl; 8 | import gr.csri.poeticon.praxicon.db.entities.Concept; 9 | import gr.csri.poeticon.praxicon.db.entities.Concept.Status; 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | /** 14 | * 15 | * @author dmavroeidis 16 | * 17 | */ 18 | public interface ConceptDao extends Dao { 19 | 20 | List getAllConcepts(); 21 | 22 | List getAllBasicLevelConcepts(); 23 | 24 | List getAllNonBasicLevelConcepts(); 25 | 26 | Concept getConceptByConceptId(long conceptId); 27 | 28 | Concept getConcept(Concept concept); 29 | 30 | List getConceptsByName(String name); 31 | 32 | Concept getConceptByNameExact(String name); 33 | 34 | List getConceptsByNameAndStatus(String Name, Status status); 35 | 36 | List getConceptsByExternalSourceId(String externalSourceId); 37 | 38 | Concept getConceptByExternalSourceIdExact(String externalSourceId); 39 | 40 | List getConceptsByLanguageRepresentation(String queryString); 41 | 42 | List getConceptsByLanguageRepresentationExact(String queryString); 43 | 44 | List getConceptsByLanguageRepresentationStartsWith( 45 | String queryString); 46 | 47 | List getConceptsByLanguageRepresentationEndsWith( 48 | String queryString); 49 | 50 | List getConceptsByStatus(Status status); 51 | 52 | Concept getConceptWithExternalSourceIdOrId(String v); 53 | 54 | Concept updatedConcept(Concept newConcept); 55 | 56 | void update(Concept newConcept); 57 | 58 | void update(Concept oldConcept, Concept newConcept); 59 | 60 | List getChildren(Concept concept); 61 | 62 | List getParents(Concept concept); 63 | 64 | List getAllAncestors(Concept concept); 65 | 66 | List getAllOffsprings(Concept concept); 67 | 68 | List getClassesOfInstance(Concept concept); 69 | 70 | List getInstancesOf(Concept concept); 71 | 72 | List getBasicLevelConcepts(Concept concept); 73 | 74 | List> 75 | getBasicLevelConceptsOld(Concept concept); 76 | 77 | void clearManager(); 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/Concept_LanguageRepresentationDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao; 6 | 7 | import gr.csri.poeticon.praxicon.db.entities.Concept_LanguageRepresentation; 8 | import java.util.List; 9 | 10 | /** 11 | * 12 | * @author dmavroeidis 13 | */ 14 | public interface Concept_LanguageRepresentationDao extends 15 | Dao { 16 | 17 | List 18 | getAllConcept_LanguageRepresentations(); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/Dao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao; 6 | 7 | import java.util.List; 8 | import javax.persistence.EntityManager; 9 | import javax.persistence.Query; 10 | 11 | /** 12 | * 13 | * @author dmavroeidis 14 | * @param 15 | * @param 16 | */ 17 | public interface Dao { 18 | 19 | void persist(E entity); 20 | 21 | void merge(E entity); 22 | 23 | void remove(E entity); 24 | 25 | E findById(K id); 26 | 27 | void setEntityManager(EntityManager em); 28 | 29 | void resetAutoIncrement(); 30 | 31 | List findAll(); 32 | 33 | void removeAll(); 34 | 35 | void refresh(E entity); 36 | 37 | EntityManager getEntityManager(); 38 | 39 | void close(); 40 | 41 | void restart(); 42 | 43 | E getEntity(E entity); 44 | 45 | Query getEntityQuery(E entity); 46 | } 47 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/LanguageRepresentationDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao; 6 | 7 | import gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation; 8 | import gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation.Language; 9 | import gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation.Operator; 10 | import gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation.PartOfSpeech; 11 | import gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation.Productivity; 12 | import gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation.UseStatus; 13 | import java.util.List; 14 | 15 | /** 16 | * 17 | * @author dmavroeidis 18 | */ 19 | public interface LanguageRepresentationDao extends 20 | Dao { 21 | 22 | List getAllLanguageRepresentations(); 23 | 24 | LanguageRepresentation getSingleLanguageRepresentation( 25 | Language language, String text, PartOfSpeech pos, 26 | UseStatus useStatus, Productivity productivity, String negation, 27 | Operator operator); 28 | 29 | List getLanguageRepresentations(String text); 30 | 31 | List getLanguageRepresentations( 32 | Language language, String text, PartOfSpeech pos, 33 | UseStatus useStatus); 34 | 35 | LanguageRepresentation getLanguageRepresentationsCaseInsensitive( 36 | Language language, String text, PartOfSpeech pos, 37 | UseStatus useStatus); 38 | 39 | List getAllLanguageRepresentationText(); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/MotoricRepresentationDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao; 6 | 7 | import gr.csri.poeticon.praxicon.db.entities.MotoricRepresentation; 8 | import javax.persistence.Query; 9 | 10 | /** 11 | * 12 | * @author dmavroeidis 13 | */ 14 | public interface MotoricRepresentationDao extends 15 | Dao { 16 | 17 | @Override 18 | Query getEntityQuery(MotoricRepresentation motoricRepresentation); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/RelationArgumentDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao; 6 | 7 | import gr.csri.poeticon.praxicon.db.entities.Concept; 8 | import gr.csri.poeticon.praxicon.db.entities.RelationArgument; 9 | import gr.csri.poeticon.praxicon.db.entities.RelationSet; 10 | import java.util.List; 11 | 12 | /** 13 | * 14 | * @author dmavroeidis 15 | */ 16 | public interface RelationArgumentDao extends Dao { 17 | 18 | List getAllRelationArguments(); 19 | 20 | RelationArgument getRelationArgument(Concept concept); 21 | 22 | RelationArgument getRelationArgument(RelationSet relationSet); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/RelationDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao; 6 | 7 | import gr.csri.poeticon.praxicon.db.entities.Concept; 8 | import gr.csri.poeticon.praxicon.db.entities.Relation; 9 | import gr.csri.poeticon.praxicon.db.entities.RelationArgument; 10 | import gr.csri.poeticon.praxicon.db.entities.RelationType; 11 | import java.util.List; 12 | 13 | /** 14 | * 15 | * @author dmavroeidis 16 | */ 17 | public interface RelationDao extends Dao { 18 | 19 | Relation getRelation(RelationArgument leftArgument, 20 | RelationArgument rightArgument, 21 | RelationType.RelationNameForward relationType); 22 | 23 | List getAllRelationsOfConcept(Concept concept); 24 | 25 | boolean areRelated(Concept concept1, Concept concept2); 26 | 27 | List getRelationsByConceptRelationType( 28 | Concept concept, RelationType.RelationNameForward relationType); 29 | 30 | List getRelationsByLeftConceptTypeOfRelation( 31 | Concept concept, RelationType.RelationNameForward relationType); 32 | 33 | List getRelationsByRightConceptTypeOfRelation( 34 | Concept concept, RelationType.RelationNameForward relationType); 35 | 36 | List getRelationsByRelationType( 37 | RelationType.RelationNameForward relationType); 38 | 39 | List getAllRelationsOfRelationArgument( 40 | RelationArgument relationArgument); 41 | 42 | boolean areRelated(RelationArgument relationArgument1, 43 | RelationArgument relationArgument2); 44 | 45 | List getRelationsByRelationArgumentRelationType( 46 | RelationArgument relationArgument, 47 | RelationType.RelationNameForward relationType); 48 | 49 | List getRelationsByLeftRelationArgumentTypeOfRelation( 50 | RelationArgument relationArgument, 51 | RelationType.RelationNameForward relationType); 52 | 53 | List getRelationsByRightRelationArgumentTypeOfRelation( 54 | RelationArgument relationArgument, 55 | RelationType.RelationNameForward relationType); 56 | 57 | Relation updatedRelation(Relation newRelation); 58 | 59 | Relation getRelation(Relation newRelation); 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/RelationSetDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao; 6 | 7 | import gr.csri.poeticon.praxicon.db.entities.Concept; 8 | import gr.csri.poeticon.praxicon.db.entities.Relation; 9 | import gr.csri.poeticon.praxicon.db.entities.RelationArgument; 10 | import gr.csri.poeticon.praxicon.db.entities.RelationSet; 11 | import java.util.List; 12 | 13 | /** 14 | * 15 | * @author dmavroeidis 16 | */ 17 | public interface RelationSetDao extends Dao { 18 | 19 | RelationSet getRelationSetByName(String relationSetName); 20 | 21 | RelationSet getRelationSet(RelationSet relationSet); 22 | 23 | List getRelationSetsByRelationArgument( 24 | RelationArgument relationArgument); 25 | 26 | List getRelationSetsByRelation(Relation relation); 27 | 28 | List getRelationSetsByConcept(Concept concept); 29 | 30 | List getRelationSetsWithRelationArgumentAsLeftArgument( 31 | RelationArgument relationArgument); 32 | 33 | List getRelationSetsWithRelationArgumentAsRightArgument( 34 | RelationArgument relationArgument); 35 | 36 | List getRelationSetsWithConceptAsRightArgument( 37 | Concept concept); 38 | 39 | RelationSet updatedRelationSet(RelationSet relationSet); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/RelationTypeDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao; 6 | 7 | import gr.csri.poeticon.praxicon.db.entities.RelationType; 8 | 9 | /** 10 | * 11 | * @author dmavroeidis 12 | */ 13 | public interface RelationTypeDao extends Dao { 14 | 15 | RelationType getRelationTypeByForwardName( 16 | RelationType.RelationNameForward forwardName); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/VisualRepresentationDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao; 6 | 7 | import gr.csri.poeticon.praxicon.db.entities.VisualRepresentation; 8 | 9 | /** 10 | * 11 | * @author dmavroeidis 12 | */ 13 | public interface VisualRepresentationDao extends 14 | Dao { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/implSQL/Concept_LanguageRepresentationDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao.implSQL; 6 | 7 | import gr.csri.poeticon.praxicon.db.dao.Concept_LanguageRepresentationDao; 8 | import gr.csri.poeticon.praxicon.db.entities.Concept_LanguageRepresentation; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | import javax.persistence.Query; 12 | 13 | /** 14 | * 15 | * @author dmavroeidis 16 | */ 17 | public class Concept_LanguageRepresentationDaoImpl extends 18 | JpaDao implements 19 | Concept_LanguageRepresentationDao { 20 | 21 | /** 22 | * Finds all the Language Representations. 23 | * 24 | * @return a list of all Language Representations in the database 25 | */ 26 | @Override 27 | public List 28 | getAllConcept_LanguageRepresentations() { 29 | Query query = getEntityManager().createNamedQuery( 30 | "findAllConcept_LanguageRepresentations"); 31 | List retrievedConcept_LanguageRepresentationsList = 32 | new ArrayList<>(query.getResultList()); 33 | return retrievedConcept_LanguageRepresentationsList; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/implSQL/JpaDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao.implSQL; 6 | 7 | import gr.csri.poeticon.praxicon.EntityMngFactory; 8 | import gr.csri.poeticon.praxicon.db.dao.Dao; 9 | import java.lang.reflect.ParameterizedType; 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | import static java.util.Objects.isNull; 13 | import javax.persistence.EntityManager; 14 | import javax.persistence.Query; 15 | 16 | /** 17 | * 18 | * @author dmavroeidis 19 | * @param 20 | * @param 21 | */ 22 | public abstract class JpaDao implements Dao { 23 | 24 | protected Class entityClass; 25 | 26 | protected EntityManager entityManager; 27 | 28 | public JpaDao() { 29 | ParameterizedType genericSuperclass = 30 | (ParameterizedType)getClass().getGenericSuperclass(); 31 | this.entityClass = 32 | (Class)genericSuperclass.getActualTypeArguments()[1]; 33 | this.entityManager = EntityMngFactory.getEntityManager(); 34 | } 35 | 36 | public JpaDao(EntityManager entityManager) { 37 | ParameterizedType genericSuperclass = 38 | (ParameterizedType)getClass().getGenericSuperclass(); 39 | this.entityClass = 40 | (Class)genericSuperclass.getActualTypeArguments()[1]; 41 | this.entityManager = entityManager; 42 | } 43 | 44 | @Override 45 | public void setEntityManager(EntityManager em) { 46 | this.entityManager = em; 47 | } 48 | 49 | @Override 50 | public EntityManager getEntityManager() { 51 | return this.entityManager; 52 | } 53 | 54 | @Override 55 | public void persist(E entity) { 56 | if (!entityManager.getTransaction().isActive()) { 57 | entityManager.getTransaction().begin(); 58 | } 59 | try { 60 | entityManager.persist(entity); 61 | entityManager.flush(); 62 | entityManager.getTransaction().commit(); 63 | } catch (Exception e) { 64 | e.printStackTrace(); 65 | entityManager.getTransaction().rollback(); 66 | } finally { 67 | 68 | } 69 | } 70 | 71 | @Override 72 | public void merge(E entity) { 73 | if (!entityManager.getTransaction().isActive()) { 74 | entityManager.getTransaction().begin(); 75 | } 76 | try { 77 | entityManager.merge(entity); 78 | entityManager.flush(); 79 | entityManager.getTransaction().commit(); 80 | } catch (Exception e) { 81 | e.printStackTrace(); 82 | entityManager.getTransaction().rollback(); 83 | } finally { 84 | 85 | } 86 | } 87 | 88 | @Override 89 | public void remove(E entity) { 90 | if (!entityManager.getTransaction().isActive()) { 91 | entityManager.getTransaction().begin(); 92 | } 93 | entityManager.remove(entity); 94 | entityManager.flush(); 95 | entityManager.getTransaction().commit(); 96 | 97 | } 98 | 99 | @Override 100 | public E findById(K id) { 101 | return entityManager.find(entityClass, id); 102 | } 103 | 104 | // This is for MySQL ONLY, doesn't work for all entities. 105 | // Please override as appropriate. 106 | @Override 107 | public void resetAutoIncrement() { 108 | String name = entityClass.getName(). 109 | substring(entityClass.getName().lastIndexOf('.') + 1); 110 | if (name.endsWith("DTO")) { 111 | name = name.substring(0, name.length() - "DTO".length()); 112 | } 113 | name += "s"; 114 | name = name.substring(name.lastIndexOf('.') + 1); 115 | name = name.toUpperCase(); 116 | Query q = getEntityManager().createNativeQuery("ALTER TABLE MVCG_" + 117 | name + " AUTO_INCREMENT = 1"); 118 | q.executeUpdate(); 119 | } 120 | 121 | @SuppressWarnings("unchecked") 122 | @Override 123 | public List findAll() { 124 | Query q = getEntityManager().createQuery("SELECT h FROM " + 125 | entityClass.getName().substring(entityClass.getName(). 126 | lastIndexOf('.') + 1) + " h order by h.id"); 127 | return new ArrayList<>(q.getResultList()); 128 | } 129 | 130 | @Override 131 | public E getEntity(E entity) { 132 | Query q = getEntityQuery(entity); 133 | if (!isNull(q)) { 134 | List res = new ArrayList<>(q.getResultList()); 135 | if (res.isEmpty()) { 136 | return entity; 137 | } 138 | return (E)res.iterator().next(); 139 | } else { 140 | return entity; 141 | } 142 | } 143 | 144 | @Override 145 | public Query getEntityQuery(E entity) { 146 | return null; 147 | } 148 | 149 | @Override 150 | public void removeAll() { 151 | Query q = getEntityManager().createQuery("DELETE FROM " + 152 | entityClass.getName().substring(entityClass.getName(). 153 | lastIndexOf('.') + 1) + " h"); 154 | q.executeUpdate(); 155 | } 156 | 157 | @Override 158 | public void refresh(E entity) { 159 | getEntityManager().refresh(entity); 160 | } 161 | 162 | @Override 163 | public void close() { 164 | if (!isNull(entityManager)) { 165 | entityManager.close(); 166 | } 167 | } 168 | 169 | @Override 170 | public void restart() { 171 | EntityMngFactory.restart(); 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/implSQL/LanguageRepresentationDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao.implSQL; 6 | 7 | import gr.csri.poeticon.praxicon.db.dao.LanguageRepresentationDao; 8 | import gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation; 9 | import gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation.Language; 10 | import gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation.Operator; 11 | import gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation.PartOfSpeech; 12 | import gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation.Productivity; 13 | import gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation.UseStatus; 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | import javax.persistence.Query; 17 | 18 | /** 19 | * 20 | * @author dmavroeidis 21 | */ 22 | public class LanguageRepresentationDaoImpl extends 23 | JpaDao implements 24 | LanguageRepresentationDao { 25 | 26 | /** 27 | * Finds all the Language Representations. 28 | * 29 | * @return a list of all Language Representations in the database 30 | */ 31 | @Override 32 | public List getAllLanguageRepresentations() { 33 | Query query = getEntityManager().createNamedQuery( 34 | "findAllLanguageRepresentations"); 35 | List retrievedLanguageRepresentationsList = 36 | new ArrayList<>(query.getResultList()); 37 | return retrievedLanguageRepresentationsList; 38 | } 39 | 40 | /** 41 | * Finds the LanguageRepresentation that has the given Language, Text, Part 42 | * of Speech, Use Status, Productivity, Negation and Operator. 43 | * Overloaded. 44 | * 45 | * @param language the Language to search 46 | * @param text the text to search 47 | * @param pos the part of speech to search 48 | * @param useStatus the use status to search 49 | * @param productivity the productivity to search 50 | * @param negation the negation to search 51 | * @param operator the operator to search 52 | * 53 | * @return A LanguageRepresentation (null if not found) 54 | */ 55 | @Override 56 | public LanguageRepresentation getSingleLanguageRepresentation( 57 | Language language, String text, PartOfSpeech pos, 58 | UseStatus useStatus, Productivity productivity, String negation, 59 | Operator operator) { 60 | Query query = getEntityManager().createNamedQuery( 61 | "findLanguageRepresentation"). 62 | setParameter("text", text). 63 | setParameter("language", language). 64 | setParameter("pos", pos). 65 | setParameter("useStatus", useStatus). 66 | setParameter("productivity", productivity). 67 | setParameter("negation", negation). 68 | setParameter("operator", operator); 69 | List retrievedLanguageRepresentationList = 70 | new ArrayList<>(query.getResultList()); 71 | if (retrievedLanguageRepresentationList.isEmpty()) { 72 | return null; 73 | } 74 | return retrievedLanguageRepresentationList.iterator().next(); 75 | } 76 | 77 | /** 78 | * Finds the LanguageRepresentation that has the given Language, Text and 79 | * Part of Speech. 80 | * Overloaded. 81 | * 82 | * @param language the Language to search 83 | * @param text the text to search 84 | * @param pos the part of speech to search 85 | * @param useStatus the use status to search 86 | * 87 | * @return A LanguageRepresentation (null if not found) 88 | */ 89 | @Override 90 | public List getLanguageRepresentations( 91 | Language language, String text, PartOfSpeech pos, 92 | UseStatus useStatus) { 93 | Query query = getEntityManager().createNamedQuery( 94 | "findLanguageRepresentationsByTextLanguagePosPStatus"). 95 | setParameter("text", text). 96 | setParameter("language", language). 97 | setParameter("pos", pos). 98 | setParameter("useStatus", useStatus); 99 | List retrievedLanguageRepresentationList = 100 | new ArrayList<>(query.getResultList()); 101 | if (retrievedLanguageRepresentationList.size() > 0) { 102 | return retrievedLanguageRepresentationList; 103 | } else { 104 | return new ArrayList<>(); 105 | } 106 | } 107 | 108 | /** 109 | * Finds the LanguageRepresentations that have text field containing the 110 | * given string Case insensitive search. 111 | * Overloaded. 112 | * 113 | * @param text the Language representation text 114 | * 115 | * @return A list of LanguageRepresentations 116 | */ 117 | @Override 118 | public List getLanguageRepresentations( 119 | String text) { 120 | Query query = getEntityManager().createNamedQuery( 121 | "findLanguageRepresentationsByText"). 122 | setParameter("text", text); 123 | return new ArrayList<>(query.getResultList()); 124 | } 125 | 126 | /** 127 | * Finds the LanguageRepresentation that has the given Language, text and 128 | * part of speech 129 | * Case insensitive search. 130 | * 131 | * @param language the Language to search 132 | * @param text the text to search 133 | * @param pos the pos to search 134 | * @param useStatus 135 | * 136 | * @return A LanguageRepresentation (null if not found) 137 | */ 138 | @Override 139 | public LanguageRepresentation getLanguageRepresentationsCaseInsensitive( 140 | Language language, String text, PartOfSpeech pos, 141 | UseStatus useStatus) { 142 | Query query = getEntityManager().createNamedQuery( 143 | "findLanguageRepresentationsBy" + 144 | "TextLanguagePosPStatusCaseInsensitive"). 145 | setParameter("text", text). 146 | setParameter("language", language). 147 | setParameter("pos", pos). 148 | setParameter("useStatus", useStatus); 149 | List retrievedLanguageRepresentationList = 150 | new ArrayList<>(query.getResultList()); 151 | if (retrievedLanguageRepresentationList.size() > 0) { 152 | return retrievedLanguageRepresentationList.iterator().next(); 153 | } else { 154 | return new LanguageRepresentation(); 155 | } 156 | } 157 | 158 | /** 159 | * Gets all LanguageRepresentation Texts. 160 | * Overloaded. 161 | * 162 | * @return A list of LanguageRepresentation Texts 163 | */ 164 | @Override 165 | public List getAllLanguageRepresentationText() { 166 | Query query = getEntityManager().createNamedQuery( 167 | "getAllLanguageRepresentationTextByText"); 168 | return new ArrayList<>(query.getResultList()); 169 | } 170 | 171 | /** 172 | * Creates q query to search for a LanguageRepresentation using text, lang 173 | * and pos 174 | * 175 | * @param languageRepresentation The language representation 176 | * 177 | * @return a query to search for the LanguageRepresentation 178 | */ 179 | @Override 180 | public Query getEntityQuery( 181 | LanguageRepresentation languageRepresentation) { 182 | Query query = getEntityManager().createNamedQuery( 183 | "getLanguageRepresentationEntityQuery"). 184 | setParameter("text", languageRepresentation. 185 | getText().toUpperCase()). 186 | setParameter("language", languageRepresentation. 187 | getLanguage().name().toUpperCase()). 188 | setParameter("pos", languageRepresentation. 189 | getPartOfSpeech().toString().toUpperCase()). 190 | setParameter("useStatus", 191 | languageRepresentation.getUseStatus().toString(). 192 | toUpperCase()). 193 | setParameter("productivity", languageRepresentation. 194 | getProductivity().toString().toUpperCase()). 195 | setParameter("negation", languageRepresentation.getNegation(). 196 | toString().toUpperCase()). 197 | setParameter("operator", languageRepresentation.getOperator(). 198 | toString().toUpperCase()); 199 | return query; 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/implSQL/MotoricRepresentationDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao.implSQL; 6 | 7 | import gr.csri.poeticon.praxicon.db.dao.MotoricRepresentationDao; 8 | import gr.csri.poeticon.praxicon.db.entities.MotoricRepresentation; 9 | import javax.persistence.Query; 10 | 11 | /** 12 | * 13 | * @author dmavroeidis 14 | */ 15 | public class MotoricRepresentationDaoImpl 16 | extends JpaDao 17 | implements MotoricRepresentationDao { 18 | 19 | /** 20 | * Creates q query to search for a MotoricRepresentation using 21 | * representation 22 | * 23 | * @param motoricRepresentation the MotoricRepresentation to be searched 24 | * 25 | * @return a query to search for the MotoricRepresentation 26 | */ 27 | @Override 28 | public Query getEntityQuery(MotoricRepresentation motoricRepresentation) { 29 | Query query = getEntityManager().createNamedQuery( 30 | "getLanguageRepresentationEntityQuery"). 31 | setParameter("comment", 32 | motoricRepresentation.getComment().toUpperCase()); 33 | return query; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/implSQL/RelationArgumentDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao.implSQL; 6 | 7 | import gr.csri.poeticon.praxicon.db.dao.RelationArgumentDao; 8 | import gr.csri.poeticon.praxicon.db.entities.Concept; 9 | import gr.csri.poeticon.praxicon.db.entities.RelationArgument; 10 | import gr.csri.poeticon.praxicon.db.entities.RelationSet; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | import javax.persistence.Query; 14 | 15 | /** 16 | * 17 | * @author dmavroeidis 18 | * 19 | */ 20 | public class RelationArgumentDaoImpl extends JpaDao 21 | implements RelationArgumentDao { 22 | 23 | /** 24 | * Finds the relation argument that is connected with the given concept. 25 | * 26 | * @param concept the concept connected to the relation argument 27 | * 28 | * @return relationArgument 29 | */ 30 | @Override 31 | public List getAllRelationArguments() { 32 | Query query = getEntityManager().createNamedQuery( 33 | "findAllRelationArguments"); 34 | List retrievedRelationArgumentsList = 35 | new ArrayList<>(query.getResultList()); 36 | if (retrievedRelationArgumentsList.isEmpty()) { 37 | return new ArrayList<>(); 38 | } 39 | return retrievedRelationArgumentsList; 40 | } 41 | 42 | /** 43 | * Finds the relation argument that is connected with the given concept. 44 | * 45 | * @param concept the concept connected to the relation argument 46 | * 47 | * @return relationArgument 48 | */ 49 | @Override 50 | public RelationArgument getRelationArgument(Concept concept) { 51 | Query query = getEntityManager().createNamedQuery( 52 | "findRelationArgumentByConcept"). 53 | setParameter("concept", concept); 54 | List retrievedRelationArgumentsList = 55 | new ArrayList<>(query.getResultList()); 56 | if (retrievedRelationArgumentsList.isEmpty()) { 57 | return null; 58 | } 59 | return retrievedRelationArgumentsList.iterator().next(); 60 | } 61 | 62 | /** 63 | * Finds the relation argument that is connected with the given concept. 64 | * 65 | * @param concept the concept connected to the relation argument 66 | * 67 | * @return relationArgument 68 | */ 69 | @Override 70 | public RelationArgument getRelationArgument( 71 | RelationSet relationSet) { 72 | Query query = getEntityManager().createNamedQuery( 73 | "findRelationArgumentByRelationSet"). 74 | setParameter("relationSet", relationSet); 75 | List retrievedRelationArgumentsList = 76 | new ArrayList<>(query.getResultList()); 77 | if (retrievedRelationArgumentsList.isEmpty()) { 78 | return null; 79 | } 80 | return retrievedRelationArgumentsList.iterator().next(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/implSQL/RelationTypeDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao.implSQL; 6 | 7 | import gr.csri.poeticon.praxicon.db.dao.RelationTypeDao; 8 | import gr.csri.poeticon.praxicon.db.entities.RelationType; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | import javax.persistence.Query; 12 | 13 | /** 14 | * 15 | * @author dmavroeidis 16 | */ 17 | public class RelationTypeDaoImpl extends JpaDao implements 18 | RelationTypeDao { 19 | 20 | @Override 21 | public RelationType getRelationTypeByForwardName( 22 | RelationType.RelationNameForward forwardName) { 23 | Query query = getEntityManager().createNamedQuery( 24 | "getRelationTypeByForwardName"). 25 | setParameter("forwardName", forwardName); 26 | List relationsTypeList = 27 | new ArrayList<>(query.getResultList()); 28 | if (relationsTypeList.isEmpty()) { 29 | return null; 30 | } 31 | return relationsTypeList.iterator().next(); 32 | } 33 | 34 | /** 35 | * Creates q query to search for a RelationType using forward 36 | * and backward name 37 | * 38 | * @param relationType the RelationType to be searched 39 | * 40 | * @return a query to search for the RelationType 41 | */ 42 | @Override 43 | public Query getEntityQuery(RelationType relationType) { 44 | Query query = getEntityManager(). 45 | createNamedQuery("getRelationTypeEntityQuery"). 46 | setParameter("backwardName", relationType.getBackwardName()). 47 | setParameter("forwardName", relationType.getForwardName()); 48 | return query; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/implSQL/VisualRepresentationDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao.implSQL; 6 | 7 | import gr.csri.poeticon.praxicon.db.dao.VisualRepresentationDao; 8 | import gr.csri.poeticon.praxicon.db.entities.VisualRepresentation; 9 | import javax.persistence.Query; 10 | 11 | /** 12 | * 13 | * @author dmavroeidis 14 | * @author dmavroeidis 15 | */ 16 | public class VisualRepresentationDaoImpl extends 17 | JpaDao implements VisualRepresentationDao { 18 | 19 | /** 20 | * Creates q query to search for a given VisualRepresentation using media 21 | * type, representation ant prototype 22 | * 23 | * @param visualRepresentation 24 | * @param entity the VisualRepresentation to be searched 25 | * 26 | * @return a query to search for the VisualRepresentation 27 | */ 28 | @Override 29 | public Query getEntityQuery(VisualRepresentation visualRepresentation) { 30 | Query q = getEntityManager().createNamedQuery( 31 | "SELECT e FROM VisualRepresentation e " + 32 | "WHERE UPPER(e.MediaType) = :mediaType AND" + 33 | " UPPER(e.Representation) = :languageRepresentationName "); 34 | q.setParameter("mediaType", visualRepresentation.getMediaType()); 35 | q.setParameter("languageRepresentationName", visualRepresentation. 36 | getConcept().getLanguageRepresentationsNames()); 37 | return q; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/implXML/LanguageRepresentationDaoImplXML.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao.implXML; 6 | 7 | import gr.csri.poeticon.praxicon.Constants; 8 | import gr.csri.poeticon.praxicon.db.dao.LanguageRepresentationDao; 9 | import gr.csri.poeticon.praxicon.db.dao.implSQL.JpaDao; 10 | import gr.csri.poeticon.praxicon.db.entities.Concept; 11 | import gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation; 12 | import gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation.Language; 13 | import gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation.PartOfSpeech; 14 | import gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation.UseStatus; 15 | import java.util.ArrayList; 16 | import java.util.Enumeration; 17 | import java.util.List; 18 | import javax.persistence.Query; 19 | 20 | /** 21 | * 22 | * @author dmavroeidis 23 | */ 24 | public class LanguageRepresentationDaoImplXML extends 25 | JpaDao 26 | implements LanguageRepresentationDao { 27 | 28 | @Override 29 | public LanguageRepresentation getLanguageRepresentationsCaseInsensitive( 30 | Language language, String text, PartOfSpeech pos, 31 | UseStatus pragmaticStatus) { 32 | Enumeration en = Constants.globalConcepts.elements(); 33 | while (en.hasMoreElements()) { 34 | Concept concept = (Concept)en.nextElement(); 35 | for (LanguageRepresentation tmpLanguageRepresentation : concept. 36 | getLanguageRepresentations()) { 37 | if (tmpLanguageRepresentation.getLanguage().name(). 38 | equals(language) && 39 | tmpLanguageRepresentation.getText(). 40 | equalsIgnoreCase(text) && 41 | tmpLanguageRepresentation.getPartOfSpeech() == pos) { 42 | return tmpLanguageRepresentation; 43 | } 44 | } 45 | } 46 | return null; 47 | } 48 | 49 | @Override 50 | public List getLanguageRepresentations( 51 | String searchString) { 52 | List res = new ArrayList<>(); 53 | Enumeration en = Constants.globalConcepts.elements(); 54 | while (en.hasMoreElements()) { 55 | Concept concept = (Concept)en.nextElement(); 56 | for (LanguageRepresentation tmpLanguageRepresentation : concept. 57 | getLanguageRepresentations()) { 58 | if (tmpLanguageRepresentation.getText().toUpperCase(). 59 | contains(searchString.toUpperCase())) { 60 | res.add(tmpLanguageRepresentation); 61 | } 62 | } 63 | } 64 | return res; 65 | } 66 | 67 | @Override 68 | public Query getEntityQuery(LanguageRepresentation entity) { 69 | return null; 70 | } 71 | 72 | @Override 73 | public List getLanguageRepresentations( 74 | Language language, String text, PartOfSpeech pos, 75 | UseStatus pragmaticStatus) { 76 | throw new UnsupportedOperationException("Not supported yet."); 77 | } 78 | 79 | @Override 80 | public LanguageRepresentation getSingleLanguageRepresentation( 81 | Language language, String text, PartOfSpeech pos, 82 | UseStatus useStatus, 83 | LanguageRepresentation.Productivity productivity, String negation, 84 | LanguageRepresentation.Operator operator) { 85 | throw new UnsupportedOperationException("Not supported yet."); 86 | } 87 | 88 | @Override 89 | public List getAllLanguageRepresentationText() { 90 | throw new UnsupportedOperationException("Not supported yet."); 91 | } 92 | 93 | @Override 94 | public List getAllLanguageRepresentations() { 95 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/implXML/MotoricRepresentationDaoImplXML.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao.implXML; 6 | 7 | import gr.csri.poeticon.praxicon.db.dao.MotoricRepresentationDao; 8 | import gr.csri.poeticon.praxicon.db.dao.implSQL.JpaDao; 9 | import gr.csri.poeticon.praxicon.db.entities.MotoricRepresentation; 10 | import javax.persistence.Query; 11 | 12 | /** 13 | * 14 | * @author dmavroeidis 15 | */ 16 | public class MotoricRepresentationDaoImplXML 17 | extends JpaDao 18 | implements MotoricRepresentationDao { 19 | 20 | @Override 21 | public Query getEntityQuery(MotoricRepresentation entity) { 22 | return null; 23 | } 24 | 25 | // @Override 26 | // public List getEntries(Concept c) { 27 | // List res = new ArrayList<>(); 28 | // for (int i = 0; i < c.getMotoricRepresentations().size(); i++) { 29 | // res.add(c.getMotoricRepresentations().get(i)); 30 | // } 31 | // Comparator mrCom = new MotoricEntryComparator(); 32 | // Collections.sort(res, mrCom); 33 | // return res; 34 | // } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/implXML/RelationSetDaoImplXML.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao.implXML; 6 | 7 | import gr.csri.poeticon.praxicon.db.dao.RelationSetDao; 8 | import gr.csri.poeticon.praxicon.db.dao.implSQL.JpaDao; 9 | import gr.csri.poeticon.praxicon.db.entities.Concept; 10 | import gr.csri.poeticon.praxicon.db.entities.Relation; 11 | import gr.csri.poeticon.praxicon.db.entities.RelationArgument; 12 | import gr.csri.poeticon.praxicon.db.entities.RelationSet; 13 | import java.util.List; 14 | import javax.persistence.Query; 15 | 16 | /** 17 | * 18 | * @author dmavroeidis 19 | */ 20 | public class RelationSetDaoImplXML extends JpaDao 21 | implements RelationSetDao { 22 | 23 | @Override 24 | public List getRelationSetsByRelationArgument( 25 | RelationArgument relationArgument) { 26 | throw new UnsupportedOperationException("Not supported yet."); 27 | } 28 | 29 | public List getRelationSetsByConcept(Concept concept) { 30 | throw new UnsupportedOperationException("Not supported yet."); 31 | } 32 | 33 | public List getRelationSetsByRelation(Relation relation) { 34 | throw new UnsupportedOperationException("Not supported yet."); 35 | } 36 | 37 | //// @Override 38 | // public List getRelationSetsContainingConcept(Concept c) 39 | // { 40 | // List res = new ArrayList<>(); 41 | // 42 | // Enumeration en = Constants.globalConcepts.elements(); 43 | // while(en.hasMoreElements()) 44 | // { 45 | // Concept concept = (Concept)en.nextElement(); 46 | // for (int i =0; i < concept.getRelations().size(); i++) 47 | // { 48 | // for (int j = 0; j < concept.getRelations().size(); j++) 49 | // { 50 | // for (int k = 0; k < concept.getRelations().size(); k++) 51 | // { 52 | // List rc = concept.getRelations().get(k).getActualRelations(); 53 | // for (Relation rc1 : rc) { 54 | // if (rc1.getLeftArgument().getName().equalsIgnoreCase(c.getName()) || rc1.getObject().getName().equalsIgnoreCase(c.getName())) { 55 | // res.add(concept.getRelations().get(i).getIntersections().get(j).getRelations().get(k)); 56 | // break; 57 | // } 58 | // } 59 | // } 60 | // } 61 | // } 62 | // } 63 | // return res; 64 | // } 65 | @Override 66 | public RelationSet updatedRelationSet(RelationSet relationSet) { 67 | throw new UnsupportedOperationException("Not supported yet."); 68 | } 69 | 70 | /** 71 | * 72 | * @param entity 73 | * 74 | * @return null //for now 75 | */ 76 | @Override 77 | public Query getEntityQuery(RelationSet entity) { 78 | return null; 79 | } 80 | 81 | @Override 82 | public List getRelationSetsWithRelationArgumentAsRightArgument( 83 | RelationArgument relationArgument) { 84 | throw new UnsupportedOperationException("Not supported yet."); 85 | } 86 | 87 | @Override 88 | public List getRelationSetsWithConceptAsRightArgument( 89 | Concept concept) { 90 | throw new UnsupportedOperationException("Not supported yet."); 91 | } 92 | 93 | @Override 94 | public RelationSet getRelationSet(RelationSet relationSet) { 95 | throw new UnsupportedOperationException("Not supported yet."); 96 | } 97 | 98 | @Override 99 | public List getRelationSetsWithRelationArgumentAsLeftArgument( 100 | RelationArgument relationArgument) { 101 | throw new UnsupportedOperationException("Not supported yet."); 102 | } 103 | 104 | @Override 105 | public RelationSet getRelationSetByName(String relationSetName) { 106 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/dao/implXML/VisualRepresentationDaoImplXML.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.dao.implXML; 6 | 7 | import gr.csri.poeticon.praxicon.db.dao.VisualRepresentationDao; 8 | import gr.csri.poeticon.praxicon.db.dao.implSQL.JpaDao; 9 | import gr.csri.poeticon.praxicon.db.entities.VisualRepresentation; 10 | import javax.persistence.Query; 11 | 12 | /** 13 | * 14 | * @author dmavroeidis 15 | */ 16 | public class VisualRepresentationDaoImplXML 17 | extends JpaDao 18 | implements VisualRepresentationDao { 19 | 20 | @Override 21 | public Query getEntityQuery(VisualRepresentation entity) { 22 | return null; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/CollectionOfObjects.java: -------------------------------------------------------------------------------- 1 | package gr.csri.poeticon.praxicon.db.entities; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import javax.xml.bind.annotation.XmlAccessType; 6 | import javax.xml.bind.annotation.XmlAccessorType; 7 | import javax.xml.bind.annotation.XmlElement; 8 | import javax.xml.bind.annotation.XmlRootElement; 9 | 10 | /** 11 | * 12 | * @author dmavroeidis 13 | */ 14 | @XmlRootElement(name = "collectionOfObjects", namespace = 15 | "http://www.csri.gr/collectionOfObjects") 16 | @XmlAccessorType(XmlAccessType.FIELD) 17 | 18 | public class CollectionOfObjects { 19 | 20 | @XmlElement(name = "concepts") 21 | List concepts = new ArrayList<>(); 22 | 23 | @XmlElement(name = "relations") 24 | List relations = new ArrayList<>(); 25 | 26 | @XmlElement(name = "relationSets") 27 | List relationSets = new ArrayList<>(); 28 | 29 | public List getConcepts() { 30 | return concepts; 31 | } 32 | 33 | public void setConcepts(List concepts) { 34 | this.concepts = concepts; 35 | } 36 | 37 | public List getRelations() { 38 | return relations; 39 | } 40 | 41 | public void setRelations(List relations) { 42 | this.relations = relations; 43 | } 44 | 45 | public List getRelationSets() { 46 | return relationSets; 47 | } 48 | 49 | public void setRelationSets(List relationSets) { 50 | this.relationSets = relationSets; 51 | } 52 | 53 | public CollectionOfObjects() { 54 | concepts = new ArrayList<>(); 55 | relations = new ArrayList<>(); 56 | relationSets = new ArrayList<>(); 57 | } 58 | 59 | /** 60 | * Stores all concepts of the collection in the database updating 61 | * same-name entries 62 | */ 63 | public void storeCollectionOfObjects() { 64 | for (Concepts conceptList : concepts) { 65 | conceptList.storeConcepts(); 66 | } 67 | for (Relations relationList : relations) { 68 | relationList.storeRelations(); 69 | } 70 | for (RelationSets relationSetList : relationSets) { 71 | relationSetList.storeRelationSets(); 72 | } 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/Concept_LanguageRepresentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package gr.csri.poeticon.praxicon.db.entities; 7 | 8 | import java.io.Serializable; 9 | import java.util.Objects; 10 | import javax.persistence.CascadeType; 11 | import javax.persistence.Column; 12 | import javax.persistence.Entity; 13 | import javax.persistence.GeneratedValue; 14 | import javax.persistence.GenerationType; 15 | import javax.persistence.Id; 16 | import javax.persistence.JoinColumn; 17 | import javax.persistence.ManyToOne; 18 | import javax.persistence.NamedQueries; 19 | import javax.persistence.NamedQuery; 20 | import javax.persistence.Table; 21 | import javax.xml.bind.annotation.XmlAccessType; 22 | import javax.xml.bind.annotation.XmlAccessorType; 23 | import javax.xml.bind.annotation.XmlTransient; 24 | import javax.xml.bind.annotation.XmlType; 25 | 26 | /** 27 | * 28 | * @author dmavroeidis 29 | */ 30 | @XmlAccessorType(XmlAccessType.FIELD) 31 | @XmlType(name = "concept_languagerepresentation", namespace = 32 | "http://www.csri.gr/concept_languagerepresentation") 33 | @Entity 34 | @NamedQueries({ 35 | @NamedQuery(name = "findAllConcept_LanguageRepresentations", query = 36 | "FROM Concept_LanguageRepresentation clr"),}) 37 | @Table(name = "Concepts_LanguageRepresentations") 38 | public class Concept_LanguageRepresentation implements Serializable { 39 | 40 | private static final long serialVersionUID = 1L; 41 | 42 | @Id 43 | @XmlTransient 44 | @GeneratedValue(strategy = GenerationType.IDENTITY) 45 | @Column(name = "Concept_LanguageRepresentationId") 46 | private Long id; 47 | 48 | @Column(name = "RepresentativeLanguageRepresentation") 49 | private boolean isRepresentativeLanguageRepresentation; 50 | 51 | @XmlTransient 52 | @ManyToOne(optional = false) 53 | @JoinColumn(name = "ConceptId") 54 | private Concept concept; 55 | 56 | @ManyToOne(optional = false, cascade = {CascadeType.ALL}) 57 | @JoinColumn(name = "LanguageRepresentationId") 58 | private LanguageRepresentation languageRepresentation; 59 | 60 | public Long getId() { 61 | return id; 62 | } 63 | 64 | public void setId(Long id) { 65 | this.id = id; 66 | } 67 | 68 | /** 69 | * @return the concept. 70 | */ 71 | public Concept getConcept() { 72 | return concept; 73 | } 74 | 75 | public void setConcept(Concept concept) { 76 | this.concept = concept; 77 | } 78 | 79 | /** 80 | * @return whether the language representation is representative or not. 81 | */ 82 | public boolean getIsRepresentative() { 83 | return isRepresentativeLanguageRepresentation; 84 | } 85 | 86 | public void setIsRepresentative(boolean isRepresentative) { 87 | this.isRepresentativeLanguageRepresentation = isRepresentative; 88 | } 89 | 90 | /** 91 | * @return the language representation. 92 | */ 93 | public LanguageRepresentation getLanguageRepresentation() { 94 | return languageRepresentation; 95 | } 96 | 97 | public void setLanguageRepresentation( 98 | LanguageRepresentation languageRepresentation) { 99 | this.languageRepresentation = languageRepresentation; 100 | } 101 | 102 | @Override 103 | public int hashCode() { 104 | int hash = 7; 105 | hash = 73 * hash + (this.isRepresentativeLanguageRepresentation ? 1 : 106 | 0); 107 | // Do not change the following to "getLanguageRepresentation()". 108 | // It just won't work... 109 | hash = 73 * hash + Objects.hashCode(this.languageRepresentation); 110 | return hash; 111 | } 112 | 113 | @Override 114 | public boolean equals(Object obj) { 115 | if (obj == null) { 116 | return false; 117 | } 118 | if (getClass() != obj.getClass()) { 119 | return false; 120 | } 121 | final Concept_LanguageRepresentation other = 122 | (Concept_LanguageRepresentation)obj; 123 | if (this.isRepresentativeLanguageRepresentation != other. 124 | getIsRepresentative()) { 125 | return false; 126 | } 127 | if (!this.languageRepresentation.equals(other. 128 | getLanguageRepresentation())) { 129 | return false; 130 | } 131 | return true; 132 | } 133 | 134 | @Override 135 | public String toString() { 136 | String conceptLanguageRepresentationString = ""; 137 | conceptLanguageRepresentationString += "[" + 138 | this.getLanguageRepresentation().toString() + ", "; 139 | conceptLanguageRepresentationString += "representative: " + 140 | this.getIsRepresentative() + "]"; 141 | return conceptLanguageRepresentationString; 142 | } 143 | 144 | } 145 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/Concepts.java: -------------------------------------------------------------------------------- 1 | package gr.csri.poeticon.praxicon.db.entities; 2 | 3 | import gr.csri.poeticon.praxicon.db.dao.ConceptDao; 4 | import gr.csri.poeticon.praxicon.db.dao.LanguageRepresentationDao; 5 | import gr.csri.poeticon.praxicon.db.dao.implSQL.ConceptDaoImpl; 6 | import gr.csri.poeticon.praxicon.db.dao.implSQL.LanguageRepresentationDaoImpl; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import static java.util.Objects.isNull; 10 | import javax.xml.bind.annotation.XmlAccessType; 11 | import javax.xml.bind.annotation.XmlAccessorType; 12 | import javax.xml.bind.annotation.XmlElement; 13 | import javax.xml.bind.annotation.XmlRootElement; 14 | 15 | /** 16 | * 17 | * @author dmavroeidis 18 | */ 19 | @XmlRootElement(name = "concepts") 20 | @XmlAccessorType(XmlAccessType.FIELD) 21 | 22 | public class Concepts { 23 | 24 | @XmlElement(name = "concept") 25 | List concepts = new ArrayList<>(); 26 | 27 | public List getConcepts() { 28 | return concepts; 29 | } 30 | 31 | public void setConcepts(List concepts) { 32 | this.concepts = concepts; 33 | } 34 | 35 | public Concepts() { 36 | concepts = new ArrayList<>(); 37 | } 38 | 39 | /** 40 | * Stores all concepts of the collection in the database checking if they 41 | * already exist in the database. 42 | */ 43 | public void storeConcepts() { 44 | if (!concepts.isEmpty()) { 45 | ConceptDao cDao = new ConceptDaoImpl(); 46 | for (Concept concept : concepts) { 47 | storeConcept(concept); 48 | cDao.getEntityManager().clear(); 49 | System.out.println("Storing Concept: " + concept.toString()); 50 | } 51 | } 52 | } 53 | 54 | /** 55 | * Stores a concept in the database checking if it already exists. 56 | * 57 | * @param concept 58 | * 59 | * @return a concept 60 | */ 61 | public Concept storeConcept(Concept concept) { 62 | ConceptDao cDao = new ConceptDaoImpl(); 63 | Concept oldConcept = new Concept(concept, false, false, false); 64 | 65 | Concept retrievedConcept = cDao.getConcept(concept); 66 | Concept newConcept; 67 | // If concept does not exist in the database, store it. 68 | if (!isNull(retrievedConcept)) { 69 | // Set new concept to retrieved one so as to update it 70 | newConcept = retrievedConcept; 71 | } else { 72 | newConcept = oldConcept; 73 | } 74 | 75 | // For each language representation, find it in the DB. 76 | // If it exists, attach it to the concept. 77 | // If it doesn't exist, create it. 78 | LanguageRepresentationDao lrDao = 79 | new LanguageRepresentationDaoImpl(); 80 | 81 | if (!concept.getLanguageRepresentations().isEmpty()) { 82 | for (LanguageRepresentation languageRepresentation 83 | : concept.getLanguageRepresentations()) { 84 | LanguageRepresentation retrievedLanguageRepresentation = 85 | lrDao.getSingleLanguageRepresentation( 86 | languageRepresentation.getLanguage(), 87 | languageRepresentation.getText(), 88 | languageRepresentation.getPartOfSpeech(), 89 | languageRepresentation.getUseStatus(), 90 | languageRepresentation.getProductivity(), 91 | languageRepresentation.getNegation(), 92 | languageRepresentation.getOperator()); 93 | // if Language Representation exists add the retrieved, 94 | // otherwise, add the new one. 95 | if (!isNull(retrievedLanguageRepresentation)) { 96 | //check if already assigned to concept 97 | if (!newConcept.getLanguageRepresentations().contains( 98 | retrievedLanguageRepresentation)) { 99 | newConcept.addLanguageRepresentation( 100 | retrievedLanguageRepresentation, 101 | retrievedLanguageRepresentation. 102 | getIsRepresentative(newConcept)); 103 | } 104 | } else { 105 | LanguageRepresentation newLanguageRepresentation = 106 | new LanguageRepresentation(languageRepresentation); 107 | //check if already assigned to concept 108 | if (!newConcept.getLanguageRepresentations(). 109 | contains(newLanguageRepresentation)) { 110 | newConcept.addLanguageRepresentation( 111 | newLanguageRepresentation, 112 | languageRepresentation.getIsRepresentative( 113 | concept)); 114 | } 115 | } 116 | } 117 | } 118 | 119 | // If Motoric Representations exist, add them to new concept 120 | if (!concept.getMotoricRepresentations().isEmpty()) { 121 | for (MotoricRepresentation mr : concept. 122 | getMotoricRepresentations()) { 123 | mr.setConcept(newConcept); 124 | //check if already assigned to concept 125 | if (!newConcept.getMotoricRepresentations().contains(mr)) { 126 | newConcept.addMotoricRepresentation(mr); 127 | } 128 | } 129 | } 130 | 131 | // If Visual Representations exist, add them to new concept 132 | if (!concept.getVisualRepresentations().isEmpty() && 133 | !isNull(concept.getVisualRepresentations())) { 134 | for (VisualRepresentation vr : concept.getVisualRepresentations()) { 135 | vr.setConcept(newConcept); 136 | //check if already assigned to concept 137 | if (!newConcept.getVisualRepresentations().contains(vr)) { 138 | newConcept.addVisualRepresentation(vr); 139 | } 140 | } 141 | } 142 | 143 | // If Ontological Domains exist, add them to new concept 144 | if (!concept.getOntologicalDomains().isEmpty()) { 145 | for (OntologicalDomain od : concept.getOntologicalDomains()) { 146 | //check if already assigned to concept 147 | if (!newConcept.getOntologicalDomains().contains(od)) { 148 | newConcept.addOntologicalDomain(od); 149 | } 150 | } 151 | } 152 | 153 | // If Concept doesn't exist, add it 154 | if (isNull(retrievedConcept)) { 155 | cDao.persist(newConcept); 156 | return newConcept; 157 | } else { 158 | cDao.merge(retrievedConcept); 159 | return retrievedConcept; 160 | } 161 | 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/ConstraintValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.entities; 6 | 7 | /** 8 | * 9 | * @author dmavroeidis 10 | */ 11 | class ConstraintValidator { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/MotoricRepresentation.java: -------------------------------------------------------------------------------- 1 | package gr.csri.poeticon.praxicon.db.entities; 2 | 3 | import java.io.Serializable; 4 | import java.net.URI; 5 | import java.util.List; 6 | import java.util.Objects; 7 | import javax.persistence.CascadeType; 8 | import javax.persistence.Column; 9 | import javax.persistence.Entity; 10 | import javax.persistence.EnumType; 11 | import javax.persistence.Enumerated; 12 | import javax.persistence.GeneratedValue; 13 | import javax.persistence.GenerationType; 14 | import javax.persistence.Id; 15 | import javax.persistence.JoinColumn; 16 | import javax.persistence.ManyToOne; 17 | import javax.persistence.NamedQueries; 18 | import javax.persistence.NamedQuery; 19 | import javax.persistence.OneToMany; 20 | import javax.persistence.Table; 21 | import javax.validation.constraints.NotNull; 22 | import javax.xml.bind.annotation.XmlAccessType; 23 | import javax.xml.bind.annotation.XmlAccessorType; 24 | import javax.xml.bind.annotation.XmlTransient; 25 | import javax.xml.bind.annotation.XmlType; 26 | import org.apache.commons.lang.builder.EqualsBuilder; 27 | 28 | /** 29 | * 30 | * @author dmavroeidis 31 | * 32 | */ 33 | @XmlAccessorType(XmlAccessType.FIELD) 34 | @XmlType(name = "motoric_representation", 35 | namespace = "http://www.csri.gr/motoric_representation") 36 | @Entity 37 | @NamedQueries({ 38 | @NamedQuery(name = "getMotoricRepresentationEntityQuery", query = 39 | "FROM MotoricRepresentation mr " + 40 | "WHERE UPPER(mr.comment) = :comment"),}) 41 | @Table(name = "MotoricRepresentations"//, 42 | // uniqueConstraints = { 43 | // @UniqueConstraint(columnNames = {"PerformingAgent", "Source", "URI" 44 | // }),} 45 | ) 46 | public class MotoricRepresentation implements Serializable { 47 | 48 | public static enum PerformingAgent { 49 | 50 | ADULT, CHILD, ICUB, NAO, PR2; 51 | 52 | @Override 53 | public String toString() { 54 | return this.name(); 55 | } 56 | } 57 | 58 | private static final long serialVersionUID = 1L; 59 | @Id 60 | @XmlTransient 61 | @GeneratedValue(strategy = GenerationType.IDENTITY) 62 | @Column(name = "MotoricRepresentationId") 63 | private Long id; 64 | 65 | @Column(name = "PerformingAgent") 66 | @NotNull(message = "Performing agent must be specified.") 67 | @Enumerated(EnumType.STRING) 68 | private PerformingAgent performingAgent; 69 | 70 | @Column(name = "Source") 71 | private String source; 72 | 73 | @Column(name = "URI") 74 | @NotNull(message = "URI must be specified.") 75 | private URI uri; 76 | 77 | @Column(name = "Comment") 78 | private String comment; 79 | 80 | @XmlTransient 81 | @ManyToOne 82 | @JoinColumn(name = "concept_ConceptId") 83 | private Concept concept; 84 | 85 | @XmlTransient 86 | @ManyToOne 87 | @JoinColumn(name = "relationSet_RelationSetId") 88 | private RelationSet relationSet; 89 | 90 | @OneToMany(cascade = {CascadeType.ALL}, mappedBy = "motoricRepresentation") 91 | private List visualRepresentations; 92 | 93 | public MotoricRepresentation() { 94 | } 95 | 96 | public Long getId() { 97 | return id; 98 | } 99 | 100 | public void setId(Long id) { 101 | this.id = id; 102 | } 103 | 104 | /** 105 | * @return the source of the visual representation. 106 | * This can be ImageNet, GoogleImages, etc. 107 | */ 108 | public PerformingAgent getPerformingAgent() { 109 | return performingAgent; 110 | } 111 | 112 | public void setPerformingAgent(PerformingAgent performingAgent) { 113 | this.performingAgent = performingAgent; 114 | } 115 | 116 | /** 117 | * @return the concept related to this Motoric Representation 118 | */ 119 | public Concept getConcept() { 120 | return concept; 121 | } 122 | 123 | public void setConcept(Concept concept) { 124 | this.concept = concept; 125 | } 126 | 127 | /** 128 | * @return the relation set related to this Motoric Representation 129 | */ 130 | public RelationSet getRelationSet() { 131 | return relationSet; 132 | } 133 | 134 | public void setRelationSet(RelationSet relationSet) { 135 | this.relationSet = relationSet; 136 | } 137 | 138 | public List getVisualRepresentation() { 139 | return visualRepresentations; 140 | } 141 | 142 | public void setVisualRepresentation( 143 | List visualRepresentations) { 144 | this.visualRepresentations = visualRepresentations; 145 | } 146 | 147 | /** 148 | * @return the source of the visual representation. 149 | * This can be ImageNet, GoogleImages, etc. 150 | */ 151 | public String getSource() { 152 | return source; 153 | } 154 | 155 | public void setSource(String source) { 156 | this.source = source; 157 | } 158 | 159 | /** 160 | * @return the source of the visual representation. 161 | * This can be ImageNet, GoogleImages, etc. 162 | */ 163 | public URI getUri() { 164 | return uri; 165 | } 166 | 167 | public void setUri(URI uri) { 168 | this.uri = uri; 169 | } 170 | 171 | public void setUri(String uri) { 172 | if (this.uri.resolve(uri) != null) { 173 | this.uri = this.uri.resolve(uri); 174 | } 175 | } 176 | 177 | public String getComment() { 178 | return comment; 179 | } 180 | 181 | public void setComment(String comment) { 182 | this.comment = comment; 183 | } 184 | 185 | @Override 186 | public int hashCode() { 187 | int hash = 7; 188 | hash = 17 * hash + Objects.hashCode(this.performingAgent); 189 | hash = 17 * hash + Objects.hashCode(this.source); 190 | hash = 17 * hash + Objects.hashCode(this.uri); 191 | return hash; 192 | } 193 | 194 | @Override 195 | /* 196 | * TODO: Create a realistic equals() method 197 | */ 198 | public boolean equals(Object obj) { 199 | if (obj == null) { 200 | return false; 201 | } 202 | if (getClass() != obj.getClass()) { 203 | return false; 204 | } 205 | final MotoricRepresentation other = (MotoricRepresentation)obj; 206 | EqualsBuilder eb = new EqualsBuilder(); 207 | eb.append(this.performingAgent, other.getPerformingAgent()); 208 | eb.append(this.source, other.getSource()); 209 | eb.append(this.uri, other.getUri()); 210 | return eb.isEquals(); 211 | } 212 | 213 | @Override 214 | public String toString() { 215 | return "gr.csri.poeticon.praxicon.db.entities.MotoricRepresentation" + 216 | "[id=" + id + "]"; 217 | } 218 | 219 | } 220 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/OntologicalDomain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package gr.csri.poeticon.praxicon.db.entities; 7 | 8 | import java.io.Serializable; 9 | import java.util.List; 10 | import java.util.Objects; 11 | import javax.persistence.Column; 12 | import javax.persistence.Entity; 13 | import javax.persistence.GeneratedValue; 14 | import javax.persistence.GenerationType; 15 | import javax.persistence.Id; 16 | import javax.persistence.JoinColumn; 17 | import javax.persistence.JoinTable; 18 | import javax.persistence.ManyToMany; 19 | import javax.persistence.Table; 20 | import javax.xml.bind.annotation.XmlAccessType; 21 | import javax.xml.bind.annotation.XmlAccessorType; 22 | import javax.xml.bind.annotation.XmlTransient; 23 | import javax.xml.bind.annotation.XmlType; 24 | import org.apache.commons.lang.builder.EqualsBuilder; 25 | 26 | /** 27 | * 28 | * @author dmavroeidis 29 | */ 30 | @XmlAccessorType(XmlAccessType.FIELD) 31 | @XmlType(name = "ontological_domain", 32 | namespace = "http://www.csri.gr/ontological_domain") 33 | @Entity 34 | @Table(name = "OntologicalDomains") 35 | 36 | public class OntologicalDomain implements Serializable { 37 | 38 | private static final long serialVersionUID = 1L; 39 | @Id 40 | @XmlTransient 41 | @Column(name = "OntologicalDomainId") 42 | @GeneratedValue(strategy = GenerationType.IDENTITY) 43 | private Long id; 44 | 45 | @Column(name = "DomainName") 46 | private String domainName; 47 | 48 | @XmlTransient 49 | @ManyToMany 50 | @JoinTable( 51 | name = "OntologicalDomain_Concept", 52 | joinColumns = { 53 | @JoinColumn(name = "OntologicalDomainId")}, 54 | inverseJoinColumns = { 55 | @JoinColumn(name = "ConceptId")} 56 | ) 57 | private List concepts; 58 | 59 | /** 60 | * Gets the id of the OntologicalDomain. 61 | * 62 | * @return long 63 | */ 64 | public Long getId() { 65 | return id; 66 | } 67 | 68 | /** 69 | * Sets the id of the OntologicalDomain. 70 | * 71 | * @param id 72 | */ 73 | public void setId(Long id) { 74 | this.id = id; 75 | } 76 | 77 | /** 78 | * Gets the name of the OntologicalDomain. 79 | * 80 | * @return String 81 | */ 82 | public String getDomainName() { 83 | return domainName; 84 | } 85 | 86 | /** 87 | * Sets the name of the OntologicalDomain. 88 | * 89 | * @param domainName 90 | */ 91 | public void setDomainName(String domainName) { 92 | this.domainName = domainName; 93 | } 94 | 95 | /** 96 | * Gets the concepts that belong to an ontological domain. 97 | * 98 | * @return a set containing concepts 99 | * 100 | */ 101 | public final List getConcepts() { 102 | return concepts; 103 | } 104 | 105 | /** 106 | * Sets the concepts that belong to this ontological domain. 107 | * 108 | * @param concepts a set of concepts 109 | * 110 | */ 111 | public void setConcepts(List concepts) { 112 | this.concepts = concepts; 113 | } 114 | 115 | @Override 116 | public int hashCode() { 117 | int hash = 5; 118 | hash = 53 * hash + Objects.hashCode(this.domainName); 119 | return hash; 120 | } 121 | 122 | @Override 123 | public boolean equals(Object obj) { 124 | if (obj == null) { 125 | return false; 126 | } 127 | if (getClass() != obj.getClass()) { 128 | return false; 129 | } 130 | final OntologicalDomain other = (OntologicalDomain)obj; 131 | EqualsBuilder eb = new EqualsBuilder(); 132 | eb.append(this.domainName, other.getDomainName()); 133 | return eb.isEquals(); 134 | } 135 | 136 | @Override 137 | public String toString() { 138 | return "gr.csri.poeticon.praxicon.db.entities.OntologicalDomain[ id=" + 139 | id + " ]"; 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/Relation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.entities; 6 | 7 | import gr.csri.poeticon.praxicon.db.dao.RelationTypeDao; 8 | import gr.csri.poeticon.praxicon.db.dao.implSQL.RelationTypeDaoImpl; 9 | import java.io.Serializable; 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | import java.util.Objects; 13 | import javax.persistence.CascadeType; 14 | import javax.persistence.Column; 15 | import javax.persistence.Entity; 16 | import javax.persistence.EnumType; 17 | import javax.persistence.Enumerated; 18 | import javax.persistence.GeneratedValue; 19 | import javax.persistence.GenerationType; 20 | import javax.persistence.Id; 21 | import javax.persistence.Index; 22 | import javax.persistence.ManyToOne; 23 | import javax.persistence.NamedQueries; 24 | import javax.persistence.NamedQuery; 25 | import javax.persistence.OneToMany; 26 | import javax.persistence.Table; 27 | import javax.validation.constraints.NotNull; 28 | import javax.xml.bind.annotation.XmlAccessType; 29 | import javax.xml.bind.annotation.XmlAccessorType; 30 | import javax.xml.bind.annotation.XmlRootElement; 31 | import javax.xml.bind.annotation.XmlTransient; 32 | import javax.xml.bind.annotation.XmlType; 33 | import org.apache.commons.lang.builder.EqualsBuilder; 34 | 35 | /** 36 | * 37 | * @author dmavroeidis 38 | * 39 | */ 40 | @XmlAccessorType(XmlAccessType.FIELD) 41 | @XmlType(name = "relation", namespace = "http://www.csri.gr/relation") 42 | @XmlRootElement(name = "relation", namespace = "http://www.csri.gr/relation") 43 | @Entity 44 | @NamedQueries({ 45 | @NamedQuery(name = 46 | "findRelationsByRelationArgumentRightArgumentOrLeftArgument", 47 | query = 48 | "SELECT r FROM Relation r " + 49 | "WHERE (r.rightArgument = :relationArgument " + 50 | "OR r.leftArgument = :relationArgument)"), 51 | @NamedQuery(name = "findRelationsByRelationArgumentRelationType", query = 52 | "SELECT r FROM Relation r " + 53 | "JOIN r.relationType rt " + 54 | "WHERE (r.leftArgument = :relationArgument " + 55 | "OR r.rightArgument = :relationArgument) " + 56 | "AND rt.forwardName = :relationType"), 57 | @NamedQuery(name = "findRelation", query = 58 | "SELECT r FROM Relation r " + 59 | "JOIN r.relationType rt " + 60 | "WHERE (r.leftArgument = :leftRelationArgument " + 61 | "AND r.rightArgument = :rightRelationArgument) " + 62 | "AND rt.forwardName = :relationType"), 63 | @NamedQuery(name = "findRelationsByRelationType", query = 64 | "SELECT r FROM Relation r " + 65 | "JOIN r.relationType rt " + 66 | "WHERE rt.forwardName = :relationType"), 67 | @NamedQuery(name = "findRelationsByRightRelationArgument", query = 68 | "SELECT r FROM Relation r " + 69 | "WHERE r.rightArgument = :relationArgument"), 70 | @NamedQuery(name = "findRelationsByLeftRelationArgument", query = 71 | "SELECT r FROM Relation r " + 72 | "WHERE r.leftArgument = :relationArgument"), 73 | @NamedQuery(name = "findRelationsByLeftRelationArgumentRelationType", 74 | query = 75 | "SELECT r FROM Relation r " + 76 | "JOIN r.relationType rt " + 77 | "WHERE r.leftArgument = :relationArgument " + 78 | "AND rt.forwardName = :relationType"), 79 | @NamedQuery(name = "findRelationsByRightRelationArgumentRelationType", 80 | query = 81 | "SELECT r FROM Relation r " + 82 | "JOIN r.relationType rt " + 83 | "WHERE r.rightArgument = :relationArgument " + 84 | "AND rt.forwardName = :relationType"), 85 | @NamedQuery(name = "areRelated", query = 86 | "SELECT r FROM Relation r " + 87 | "WHERE (r.leftArgument = :relationArgument1 " + 88 | "AND r.rightArgument = :relationArgument2) " + 89 | "OR (r.leftArgument = :relationArgument2 " + 90 | "AND r.rightArgument = :relationArgument1)") 91 | }) 92 | @Table(name = "Relations", 93 | indexes = { 94 | @Index(columnList = "Comment"),}//, 95 | // uniqueConstraints = { 96 | // @UniqueConstraint(columnNames = { "LinguisticallySupported" 97 | // }),} 98 | ) 99 | public class Relation implements Serializable { 100 | 101 | public static enum LinguisticallySupported { 102 | 103 | YES, NO, UNKNOWN; 104 | 105 | @Override 106 | public String toString() { 107 | return this.name(); 108 | } 109 | } 110 | 111 | public static enum Inferred { 112 | 113 | YES, NO, UNKNOWN; 114 | 115 | @Override 116 | public String toString() { 117 | return this.name(); 118 | } 119 | } 120 | 121 | private static final long serialVersionUID = 1L; 122 | @Id 123 | @XmlTransient 124 | @GeneratedValue(strategy = GenerationType.IDENTITY) 125 | @Column(name = "RelationId") 126 | private Long id; 127 | 128 | @Column(name = "Comment") 129 | private String comment; 130 | 131 | @ManyToOne(optional = false) 132 | private RelationType relationType; 133 | 134 | @ManyToOne(cascade = {CascadeType.ALL}, optional = false) 135 | @NotNull(message = "LeftArgument of relation must be specified.") 136 | // @JoinColumn(name = "RelationArgumentId") 137 | private RelationArgument leftArgument; 138 | 139 | @ManyToOne(cascade = {CascadeType.ALL}, optional = false) 140 | @NotNull(message = "RightArgument of relation must be specified.") 141 | // @JoinColumn(name = "RelationArgumentId") 142 | private RelationArgument rightArgument; 143 | 144 | @XmlTransient 145 | @OneToMany(mappedBy = "relation") 146 | private List relationSet; 147 | 148 | @Column(name = "LinguisticallySupported") 149 | //@NotNull(message = "Linguistic support must be specified.") 150 | @Enumerated(EnumType.STRING) 151 | private LinguisticallySupported linguisticallySupported; 152 | 153 | @Column(name = "Inferred") 154 | @Enumerated(EnumType.STRING) 155 | private Inferred inferred; 156 | 157 | public Relation() { 158 | leftArgument = new RelationArgument(); 159 | rightArgument = new RelationArgument(); 160 | relationType = new RelationType(); 161 | linguisticallySupported = LinguisticallySupported.UNKNOWN; 162 | inferred = Inferred.UNKNOWN; 163 | comment = ""; 164 | } 165 | 166 | public Relation(Relation newRelation) { 167 | leftArgument = newRelation.getLeftArgument(); 168 | rightArgument = newRelation.getRightArgument(); 169 | relationType = newRelation.getRelationType(); 170 | linguisticallySupported = newRelation.getLinguisticallySupported(); 171 | inferred = newRelation.getInferred(); 172 | comment = ""; 173 | } 174 | 175 | public Long getId() { 176 | return id; 177 | } 178 | 179 | public void setId(Long id) { 180 | this.id = id; 181 | } 182 | 183 | /** 184 | * @return RelationArgument as leftArgument 185 | */ 186 | public RelationArgument getLeftArgument() { 187 | return leftArgument; 188 | } 189 | 190 | public void setLeftArgument(RelationArgument leftArgument) { 191 | this.leftArgument = leftArgument; 192 | } 193 | 194 | public RelationArgument getRightArgument() { 195 | return rightArgument; 196 | } 197 | 198 | public void setRightArgument(RelationArgument rightArgument) { 199 | this.rightArgument = rightArgument; 200 | } 201 | 202 | /** 203 | * @return whether linguistic support exists for this relation. 204 | */ 205 | public LinguisticallySupported getLinguisticallySupported() { 206 | return linguisticallySupported; 207 | } 208 | 209 | public void setLinguisticSupport( 210 | LinguisticallySupported linguisticallySupported) { 211 | this.linguisticallySupported = linguisticallySupported; 212 | } 213 | 214 | /** 215 | * @return whether the relation is inferred. 216 | */ 217 | public Inferred getInferred() { 218 | return inferred; 219 | } 220 | 221 | public void setInferred(Inferred inferred) { 222 | this.inferred = inferred; 223 | } 224 | 225 | /** 226 | * @return the relationType of the relation. 227 | */ 228 | public RelationType getRelationType() { 229 | return relationType; 230 | } 231 | 232 | public void setRelationType(RelationType type) { 233 | if (type.getId() == null) { 234 | RelationTypeDao tmp = new RelationTypeDaoImpl(); 235 | RelationType res = tmp.getEntity(type); 236 | if (res != null) { 237 | type = res; 238 | } 239 | } 240 | this.relationType = type; 241 | } 242 | 243 | /** 244 | * Sets the relationType of the Relation but it doesn't check if there is 245 | * the same relationType twice. 246 | * 247 | * @param type the relationType of relation 248 | */ 249 | public void setRelationTypeSimple(RelationType type) { 250 | this.relationType = type; 251 | } 252 | 253 | public String getComment() { 254 | return comment; 255 | } 256 | 257 | public void setComment(String comment) { 258 | this.comment = comment; 259 | } 260 | 261 | public List getRelationSets() { 262 | List relationSets = new ArrayList<>(); 263 | if (!relationSets.isEmpty()) { 264 | for (RelationSet_Relation item : relationSet) { 265 | relationSets.add(item.getRelationSet()); 266 | } 267 | } 268 | return relationSets; 269 | } 270 | 271 | @Override 272 | public int hashCode() { 273 | int hash = 7; 274 | hash = 59 * hash + Objects.hashCode(this.relationType); 275 | hash = 59 * hash + Objects.hashCode(this.leftArgument); 276 | hash = 59 * hash + Objects.hashCode(this.rightArgument); 277 | hash = 59 * hash + Objects.hashCode(this.linguisticallySupported); 278 | hash = 59 * hash + Objects.hashCode(this.inferred); 279 | return hash; 280 | } 281 | 282 | @Override 283 | public boolean equals(Object obj) { 284 | if (obj == null) { 285 | return false; 286 | } 287 | if (getClass() != obj.getClass()) { 288 | return false; 289 | } 290 | final Relation other = (Relation)obj; 291 | EqualsBuilder eb = new EqualsBuilder(); 292 | eb.append(this.relationType, other.getRelationType()); 293 | eb.append(this.leftArgument, other.getLeftArgument()); 294 | eb.append(this.rightArgument, other.getRightArgument()); 295 | eb.append(this.linguisticallySupported, other. 296 | getLinguisticallySupported()); 297 | eb.append(this.inferred, other.getInferred()); 298 | return eb.isEquals(); 299 | } 300 | 301 | @Override 302 | public String toString() { 303 | String finalString = ""; 304 | if (this.getLeftArgument().isConcept()) { 305 | finalString += this.getLeftArgument().getConcept().toString(); 306 | } else { 307 | finalString += this.getLeftArgument().getRelationSet().toString(); 308 | } 309 | 310 | finalString += " " + this.getRelationType().getForwardName() + " "; 311 | 312 | if (this.getRightArgument().isConcept()) { 313 | finalString += this.getRightArgument().getConcept().toString(); 314 | } else { 315 | finalString += this.getRightArgument().getRelationSet().toString(); 316 | } 317 | finalString = "[" + finalString + "]"; 318 | 319 | return finalString; 320 | } 321 | 322 | } 323 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/RelationArgument.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package gr.csri.poeticon.praxicon.db.entities; 7 | 8 | import java.io.Serializable; 9 | import java.util.Objects; 10 | import javax.persistence.Basic; 11 | import javax.persistence.CascadeType; 12 | import javax.persistence.Column; 13 | import javax.persistence.Entity; 14 | import javax.persistence.GeneratedValue; 15 | import javax.persistence.GenerationType; 16 | import javax.persistence.Id; 17 | import javax.persistence.NamedQueries; 18 | import javax.persistence.NamedQuery; 19 | import javax.persistence.OneToOne; 20 | import javax.persistence.Table; 21 | import javax.xml.bind.annotation.XmlAccessType; 22 | import javax.xml.bind.annotation.XmlAccessorType; 23 | import javax.xml.bind.annotation.XmlTransient; 24 | import javax.xml.bind.annotation.XmlType; 25 | 26 | /** 27 | * 28 | * @author dmavroeidis 29 | */ 30 | @XmlAccessorType(XmlAccessType.FIELD) 31 | @XmlType(name = "relation_argument", namespace = 32 | "http://www.csri.gr/relation_argument") 33 | @Entity 34 | @NamedQueries({ 35 | @NamedQuery(name = "findAllRelationArguments", query = 36 | "FROM RelationArgument ra"), 37 | @NamedQuery(name = "findRelationArgumentByConcept", query = 38 | "SELECT ra FROM RelationArgument ra " + 39 | "JOIN ra.concept rac " + 40 | "WHERE rac = :concept"), 41 | @NamedQuery(name = "findRelationArgumentByRelationSet", query = 42 | "SELECT ra FROM RelationArgument ra " + 43 | "JOIN ra.relationSet rars " + 44 | "WHERE rars = :relationSet"),}) 45 | @Table(name = "RelationArguments") 46 | public class RelationArgument implements Serializable { 47 | 48 | private static final long serialVersionUID = 1L; 49 | @Id 50 | @XmlTransient 51 | @GeneratedValue(strategy = GenerationType.IDENTITY) 52 | @Column(name = "RelationArgumentId") 53 | private Long id; 54 | 55 | @Basic(optional = true) 56 | @OneToOne(cascade = {CascadeType.ALL}) 57 | private Concept concept; 58 | 59 | @Basic(optional = true) 60 | @OneToOne(cascade = {CascadeType.ALL}) 61 | private RelationSet relationSet; 62 | 63 | /** 64 | * Constructor #1. Both concept and relationSet are set to null. 65 | */ 66 | public RelationArgument() { 67 | this.concept = null; 68 | this.relationSet = null; 69 | } 70 | 71 | /** 72 | * Constructor #2. concept is given and relationSet is set to null. 73 | * 74 | * @param concept 75 | */ 76 | public RelationArgument(Concept concept) { 77 | this.concept = concept; 78 | this.relationSet = null; 79 | } 80 | 81 | /** 82 | * Constructor #3. relationSet is given and concept is set to null. 83 | * 84 | * @param relationSet 85 | */ 86 | public RelationArgument(RelationSet relationSet) { 87 | this.concept = null; 88 | this.relationSet = relationSet; 89 | } 90 | 91 | /** 92 | * Constructor #4. Checks whether the argument is Concept or RelationSet 93 | * and stores it accordingly. 94 | * 95 | * @param relationArgument 96 | */ 97 | public RelationArgument(RelationArgument relationArgument) { 98 | if (relationArgument.isConcept()) { 99 | this.concept = relationArgument.getConcept(); 100 | this.relationSet = null; 101 | } 102 | if (relationArgument.isRelationSet()) { 103 | this.relationSet = relationArgument.getRelationSet(); 104 | this.concept = null; 105 | } 106 | } 107 | 108 | /** 109 | * Gets the id of this RelationArgument. 110 | * 111 | * @return Long integer. 112 | */ 113 | public Long getId() { 114 | return id; 115 | } 116 | 117 | /** 118 | * 119 | * Sets the id of this RelationArgument. 120 | * 121 | * @param id 122 | */ 123 | public void setId(Long id) { 124 | this.id = id; 125 | } 126 | 127 | /** 128 | * 129 | * @return the Concept connected with this RelationArgument (can be null) 130 | */ 131 | public Concept getConcept() { 132 | return concept; 133 | } 134 | 135 | /** 136 | * 137 | * Sets the concept of this RelationArgument. It cannot be set if the 138 | * relationSet has already been set. 139 | * 140 | * @param concept 141 | */ 142 | public void setConcept(Concept concept) { 143 | if (this.relationSet == null) { 144 | this.concept = concept; 145 | } else { 146 | System.err.println( 147 | "Cannot set concept of the relation argument " + 148 | "as a relation set is already present."); 149 | } 150 | } 151 | 152 | /** 153 | * Gets the RelationSet of this RelationArgument. 154 | * 155 | * @return the RelationSet connected with this RelationArgument 156 | * (can be null) 157 | */ 158 | public RelationSet getRelationSet() { 159 | return relationSet; 160 | } 161 | 162 | /** 163 | * Sets the RelationSet of this RelationArgument. It cannot be set if the 164 | * concept has already been set. 165 | * 166 | * @param relationSet 167 | */ 168 | public void setRelationSet(RelationSet relationSet) { 169 | if (this.concept == null) { 170 | this.relationSet = relationSet; 171 | } else { 172 | System.err.println("Cannot set relation set of the " + 173 | "relation argument as a concept is already present."); 174 | } 175 | } 176 | 177 | /** 178 | * 179 | * @return an Object structure that is either a Concept or RelationSet. 180 | */ 181 | public Object getRelationArgumentAsObject() { 182 | if (concept != null) { 183 | return (Object)this.concept; 184 | } else if (relationSet != null) { 185 | return (Object)this.relationSet; 186 | } 187 | return null; 188 | } 189 | 190 | /** 191 | * 192 | * @return the class type of this RelationArgument. 193 | * Can be either Concept or RelationSet. 194 | */ 195 | public Class getRelationArgumentClassType() { 196 | if (concept != null) { 197 | return this.concept.getClass(); 198 | } else if (relationSet != null) { 199 | return this.relationSet.getClass(); 200 | } 201 | return null; 202 | } 203 | 204 | public boolean isConcept() { 205 | return this.getRelationArgumentClassType() == Concept.class; 206 | } 207 | 208 | public boolean isRelationSet() { 209 | return this.getRelationArgumentClassType() == RelationSet.class; 210 | } 211 | 212 | @Override 213 | public int hashCode() { 214 | int hash = 7; 215 | if (this.isConcept()) { 216 | hash = 89 * hash + Objects.hashCode(this.getConcept()); 217 | } else { 218 | hash = 89 * hash + Objects.hashCode(this.getRelationSet()); 219 | } 220 | return hash; 221 | } 222 | 223 | @Override 224 | public boolean equals(Object obj) { 225 | if (obj == null) { 226 | return false; 227 | } 228 | if (getClass() != obj.getClass()) { 229 | return false; 230 | } 231 | final RelationArgument other = (RelationArgument)obj; 232 | if (this.isConcept()) { 233 | if (other.isRelationSet()) { 234 | return false; 235 | } else if (!this.concept.equals(other.getConcept())) { 236 | return false; 237 | } 238 | } else if (this.isRelationSet()) { 239 | if (other.isConcept()) { 240 | return false; 241 | } else if (!this.relationSet.equals(other.getRelationSet())) { 242 | return false; 243 | } 244 | } 245 | return true; 246 | } 247 | 248 | @Override 249 | public String toString() { 250 | if (this.isConcept()) { 251 | return this.getConcept().toString(); 252 | } else { 253 | return this.getRelationSet().toString(); 254 | } 255 | // return "gr.csri.poeticon.praxicon.db.entities.RelationArgument[ id=" + 256 | // id + " ]"; 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/RelationArguments.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * To change this license header, choose License Headers in Project Properties. 4 | * To change this template file, choose Tools | Templates 5 | * and open the template in the editor. 6 | */ 7 | package gr.csri.poeticon.praxicon.db.entities; 8 | 9 | import gr.csri.poeticon.praxicon.db.dao.RelationArgumentDao; 10 | import gr.csri.poeticon.praxicon.db.dao.implSQL.RelationArgumentDaoImpl; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | import static java.util.Objects.isNull; 14 | import javax.xml.bind.annotation.XmlAccessType; 15 | import javax.xml.bind.annotation.XmlAccessorType; 16 | import javax.xml.bind.annotation.XmlElement; 17 | import javax.xml.bind.annotation.XmlRootElement; 18 | 19 | /** 20 | * 21 | * @author dmavroeidis 22 | */ 23 | @XmlRootElement(name = "relationArguments") 24 | @XmlAccessorType(XmlAccessType.FIELD) 25 | public class RelationArguments { 26 | 27 | @XmlElement(name = "relationArgument") 28 | List relationArguments = new ArrayList<>(); 29 | 30 | public List getRelationArguments() { 31 | return relationArguments; 32 | } 33 | 34 | public void setRelationArguments(List relationArguments) { 35 | this.relationArguments = relationArguments; 36 | } 37 | 38 | public RelationArguments() { 39 | relationArguments = new ArrayList<>(); 40 | } 41 | 42 | /** 43 | * Stores all relation arguments of the collection in the database 44 | */ 45 | public void storeRelationArguments() { 46 | if (!relationArguments.isEmpty()) { 47 | RelationArgumentDao rsDao = new RelationArgumentDaoImpl(); 48 | RelationArgument newRelationArgument; 49 | for (RelationArgument relationArgument : relationArguments) { 50 | newRelationArgument = storeRelationArgument(relationArgument); 51 | rsDao.getEntityManager().clear(); 52 | System.out.println("Storing Relation Argument: " + 53 | newRelationArgument.toString()); 54 | } 55 | } 56 | } 57 | 58 | public RelationArgument storeRelationArgument( 59 | RelationArgument relationArgument) { 60 | 61 | /* 62 | * Analyze relation argument: 63 | * 0. Create a new Relation Argument. 64 | * 1. Check if the Relation Argument is a Concept or a RelationSet. 65 | * 1.a. If Concept then: 66 | * 1.a.1. Store Concept 67 | * 1.a.2. Check if the Relation Argument with this Concept 68 | * exists in the database. 69 | * 1.a.3. Add the Concept to the Relation Argument 70 | * 1.b. If Relation Set then: 71 | * 1.b.1. Store Relation Set 72 | * 1.a.2. Check if the Relation Argument with this Relation Set 73 | * exists in the database. 74 | * 1.b.1. Add the Relation Set to the Relation Argument 75 | * 2. Store the Relation Argument in the database. 76 | * 3. Return it. 77 | */ 78 | Concepts newConceptsObject = new Concepts(); 79 | RelationSets newRelationSetObject = new RelationSets(); 80 | RelationArgumentDao raDao = new RelationArgumentDaoImpl(); 81 | RelationArgument newRelationArgument; 82 | RelationArgument retrievedRelationArgument; 83 | boolean isConcept = relationArgument.isConcept(); 84 | if (isConcept) { 85 | Concept newConcept = newConceptsObject.storeConcept( 86 | relationArgument.getConcept()); 87 | retrievedRelationArgument = raDao.getRelationArgument(newConcept); 88 | if (!isNull(retrievedRelationArgument)) { 89 | newRelationArgument = retrievedRelationArgument; 90 | raDao.merge(newRelationArgument); 91 | } else { 92 | newRelationArgument = new RelationArgument(newConcept); 93 | raDao.persist(newRelationArgument); 94 | } 95 | } else { 96 | RelationSet newRelationSet = newRelationSetObject. 97 | storeRelationSet(relationArgument.getRelationSet()); 98 | retrievedRelationArgument = raDao. 99 | getRelationArgument(newRelationSet); 100 | if (!isNull(retrievedRelationArgument)) { 101 | newRelationArgument = retrievedRelationArgument; 102 | raDao.merge(newRelationArgument); 103 | } else { 104 | newRelationArgument = new RelationArgument(newRelationSet); 105 | raDao.persist(newRelationArgument); 106 | } 107 | } 108 | return newRelationArgument; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/RelationSet_Relation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package gr.csri.poeticon.praxicon.db.entities; 7 | 8 | import java.io.Serializable; 9 | import java.util.Objects; 10 | import javax.persistence.CascadeType; 11 | import javax.persistence.Column; 12 | import javax.persistence.Entity; 13 | import javax.persistence.GeneratedValue; 14 | import javax.persistence.GenerationType; 15 | import javax.persistence.Id; 16 | import javax.persistence.JoinColumn; 17 | import javax.persistence.ManyToOne; 18 | import javax.persistence.Table; 19 | import javax.xml.bind.annotation.XmlAccessType; 20 | import javax.xml.bind.annotation.XmlAccessorType; 21 | import javax.xml.bind.annotation.XmlTransient; 22 | import javax.xml.bind.annotation.XmlType; 23 | import org.apache.commons.lang.builder.EqualsBuilder; 24 | 25 | /** 26 | * 27 | * @author dmavroeidis 28 | */ 29 | @XmlAccessorType(XmlAccessType.FIELD) 30 | @XmlType(name = "relationset_relation", namespace = 31 | "http://www.csri.gr/relationset_relation") 32 | @Entity 33 | @Table(name = "RelationSets_Relations") 34 | public class RelationSet_Relation implements Serializable { 35 | 36 | private static final long serialVersionUID = 1L; 37 | @Id 38 | @XmlTransient 39 | @GeneratedValue(strategy = GenerationType.IDENTITY) 40 | @Column(name = "RelationSet_RelationId") 41 | private Long id; 42 | 43 | @XmlTransient 44 | @ManyToOne(optional = false) 45 | @JoinColumn(name = "RelationSetId") 46 | private RelationSet relationSet; 47 | 48 | @ManyToOne(cascade = {CascadeType.ALL}, optional = false) 49 | @JoinColumn(name = "RelationId") 50 | private Relation relation; 51 | 52 | public RelationSet_Relation() { 53 | this.relationSet = new RelationSet(); 54 | this.relation = new Relation(); 55 | } 56 | 57 | public Long getId() { 58 | return id; 59 | } 60 | 61 | public void setId(Long id) { 62 | this.id = id; 63 | } 64 | 65 | public Relation getRelation() { 66 | return relation; 67 | } 68 | 69 | public void setRelation(Relation relation) { 70 | this.relation = relation; 71 | } 72 | 73 | public RelationSet getRelationSet() { 74 | return relationSet; 75 | } 76 | 77 | public void setRelationSet(RelationSet relationSet) { 78 | this.relationSet = relationSet; 79 | } 80 | 81 | @Override 82 | public int hashCode() { 83 | int hash = 7; 84 | hash = 47 * hash + Objects.hashCode(this.relation); 85 | return hash; 86 | } 87 | 88 | @Override 89 | public boolean equals(Object obj) { 90 | if (obj == null) { 91 | return false; 92 | } 93 | if (getClass() != obj.getClass()) { 94 | return false; 95 | } 96 | final RelationSet_Relation other = (RelationSet_Relation)obj; 97 | EqualsBuilder eb = new EqualsBuilder(); 98 | eb.append(this.relation, other.getRelation()); 99 | return eb.isEquals(); 100 | } 101 | 102 | @Override 103 | public String toString() { 104 | return "gr.csri.poeticon.praxicon.db.entities.RelationSet_Relation" + 105 | "[ id=" + id + " ]"; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/RelationType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.entities; 6 | 7 | import java.io.Serializable; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | import static java.util.Objects.isNull; 11 | import javax.persistence.Column; 12 | import javax.persistence.Entity; 13 | import javax.persistence.EnumType; 14 | import javax.persistence.Enumerated; 15 | import javax.persistence.GeneratedValue; 16 | import javax.persistence.GenerationType; 17 | import javax.persistence.Id; 18 | import javax.persistence.NamedQueries; 19 | import javax.persistence.NamedQuery; 20 | import javax.persistence.OneToMany; 21 | import javax.persistence.Table; 22 | import javax.xml.bind.annotation.XmlAccessType; 23 | import javax.xml.bind.annotation.XmlAccessorType; 24 | import javax.xml.bind.annotation.XmlTransient; 25 | import javax.xml.bind.annotation.XmlType; 26 | 27 | /** 28 | * 29 | * @author dmavroeidis 30 | * 31 | */ 32 | @XmlAccessorType(XmlAccessType.FIELD) 33 | @XmlType(name = "relation_type", namespace = 34 | "http://www.csri.gr/relation_type") 35 | @Entity 36 | @NamedQueries({ 37 | @NamedQuery(name = "getRelationTypeEntityQuery", query = 38 | "SELECT e FROM RelationType e " + 39 | "WHERE e.forwardName = :forwardName " + 40 | "AND e.backwardName = :backwardName"), 41 | @NamedQuery(name = "getRelationTypeByForwardName", query = 42 | "SELECT rt FROM RelationType rt " + 43 | "WHERE rt.forwardName = :forwardName"),}) 44 | @Table(name = "RelationTypes"//, 45 | // uniqueConstraints = { 46 | // @UniqueConstraint(columnNames = {"ForwardName", "BackwardName"}),} 47 | ) 48 | public class RelationType implements Serializable { 49 | 50 | public static enum RelationNameForward { 51 | 52 | ACTION_AGENT, ACTION_GOAL, ACTION_OBJECT, ACTION_RESULT, ACTION_TOOL, 53 | ASPECT_ABSTRACT_ENTITY, ASPECT_ABSTRACT_FEATURE, COMPARED_WITH, 54 | ENABLES, EVENT_STEP, HAS_ANTHROPOGENIC_EFFECT, HAS_COLOUR, 55 | HAS_CONDITION, HAS_CONTENT, HAS_DENSITY, HAS_DEPTH, HAS_DIRECTION, 56 | HAS_FORCE, HAS_FREQUENCY, HAS_HEIGHT, HAS_HUE, HAS_MOTOR_PROGRAM, 57 | HAS_INSTANCE, HAS_INTENSITY, HAS_LENGTH, HAS_LOCATION, HAS_LUMINANCE, 58 | HAS_MATERIAL, HAS_MATERIAL_RESISTANCE, HAS_MEASUREMENT_UNIT, 59 | HAS_MEASUREMENT_VALUE, HAS_NATURAL_EFFECT, HAS_PART, 60 | HAS_PARTIAL_INSTANCE, HAS_REGION, HAS_SHAPE, HAS_SIZE, HAS_SPEED_RATE, 61 | HAS_TEMPERATURE, HAS_TEXTURE, HAS_TIME, HAS_VALUE, HAS_VISUAL_PATTERN, 62 | HAS_VOLUME, HAS_WEIGHT, HAS_WIDTH, LESS, MORE, TYPE_TOKEN; 63 | 64 | @Override 65 | public String toString() { 66 | return this.name(); 67 | } 68 | } 69 | 70 | public static enum RelationNameBackward { 71 | 72 | AGENT_ACTION, GOAL_ACTION, OBJECT_ACTION, RESULT_ACTION, TOOL_ACTION, 73 | ABSTRACT_ENTITY_ASPECT, ABSTRACT_FEATURE_ASPECT, ENABLED_BY, 74 | STEP_EVENT, ANTHROPOGENIC_EFFECT_OF, COLOUR_OF, CONDITION_OF, 75 | CONTENT_OF, DENSITY_OF, DEPTH_OF, DIRECTION_OF, FORCE_OF, FREQUENCY_OF, 76 | HEIGHT_OF, HUE_OF, MOTOR_PROGRAM_OF, INSTANCE_OF, INTENSITY_OF, 77 | LENGTH_OF, LOCATION_OF, LUMINANCE_OF, MATERIAL_OF, 78 | MATERIAL_RESISTANCE_OF, MEASUREMENT_UNIT_OF, MEASUREMENT_VALUE_OF, 79 | NATURAL_EFFECT_OF, PART_OF, PARTIAL_INSTANCE_OF, REGION_OF, SHAPE_OF, 80 | SIZE_OF, SPEED_RATE_OF, TEMPERATURE_OF, TEXTURE_OF, TIME_OF, VALUE_OF, 81 | VISUAL_PATTERN_OF, VOLUME_OF, WEIGHT_OF, WIDTH_OF, NO, TOKEN_TYPE; 82 | 83 | @Override 84 | public String toString() { 85 | return this.name(); 86 | } 87 | } 88 | 89 | private static final long serialVersionUID = 1L; 90 | @Id 91 | @XmlTransient 92 | @Column(name = "RelationTypeId") 93 | @GeneratedValue(strategy = GenerationType.IDENTITY) 94 | private Long id; 95 | 96 | @Column(name = "ForwardName") 97 | @Enumerated(EnumType.STRING) 98 | private RelationNameForward forwardName; 99 | 100 | @Column(name = "BackwardName") 101 | @Enumerated(EnumType.STRING) 102 | private RelationNameBackward backwardName; 103 | 104 | @XmlTransient 105 | @OneToMany(mappedBy = "relationType") 106 | private List relations; 107 | 108 | public RelationType() { 109 | relations = new ArrayList<>(); 110 | } 111 | 112 | public RelationType(String forwardName, String backwardName) { 113 | relations = new ArrayList<>(); 114 | this.setForwardName(forwardName); 115 | this.setBackwardName(backwardName); 116 | } 117 | 118 | public RelationType(RelationNameForward forwardName, 119 | RelationNameBackward backwardName) { 120 | relations = new ArrayList<>(); 121 | this.forwardName = forwardName; 122 | this.backwardName = backwardName; 123 | } 124 | 125 | /** 126 | * 127 | * @return the id of the relation type. 128 | */ 129 | public Long getId() { 130 | return id; 131 | } 132 | 133 | public void setId(Long id) { 134 | this.id = id; 135 | } 136 | 137 | public RelationNameForward getForwardName() { 138 | return forwardName; 139 | } 140 | 141 | public void setForwardName(RelationNameForward name) { 142 | this.forwardName = name; 143 | } 144 | 145 | /** 146 | * Enforces the system to use as a relation type the given string (even if 147 | * it is not a relationName). This isn't stored in the db 148 | * 149 | * @param name The forward name of the relation 150 | */ 151 | public void setForwardNameString(String name) { 152 | String tmp = name.replaceAll("-", "_"); 153 | try { 154 | this.forwardName = RelationNameForward.valueOf(tmp.toUpperCase()); 155 | } catch (Exception e) { 156 | 157 | } 158 | } 159 | 160 | public final void setForwardName(String name) { 161 | this.forwardName = RelationNameForward.valueOf(name.toUpperCase()); 162 | } 163 | 164 | /** 165 | * @return the forward name. 166 | */ 167 | public String getForwardNameString() { 168 | if (forwardName != null && !forwardName.name().equalsIgnoreCase("")) { 169 | return forwardName.name(); 170 | } 171 | return null; 172 | } 173 | 174 | public RelationNameBackward getBackwardName() { 175 | return backwardName; 176 | } 177 | 178 | public void setBackwardName(RelationNameBackward backwardName) { 179 | this.backwardName = backwardName; 180 | } 181 | 182 | public final void setBackwardName(String name) { 183 | this.backwardName = RelationNameBackward.valueOf(name.toUpperCase()); 184 | } 185 | 186 | /** 187 | * Enforces the system to use as a relation type the given string (even if 188 | * it is not a relation_name. This isn't stored in the db 189 | * 190 | * @param name The backward name of the relation 191 | */ 192 | public void setBackwardNameString(String name) { 193 | String tmp = name.replaceAll("-", "_"); 194 | try { 195 | this.backwardName = 196 | RelationNameBackward.valueOf(tmp.toUpperCase()); 197 | } catch (Exception e) { 198 | } 199 | } 200 | 201 | /** 202 | * @return the backward name as a String. 203 | */ 204 | public String getBackwardNameString() { 205 | if (backwardName != null && !backwardName.name().equalsIgnoreCase("")) { 206 | return backwardName.name(); 207 | } 208 | return null; 209 | } 210 | 211 | public List getRelations() { 212 | return relations; 213 | } 214 | 215 | public void setRelations(List relations) { 216 | this.relations = relations; 217 | } 218 | 219 | public void addRelation(Relation relation) { 220 | relation.setRelationType(this); 221 | this.relations.add(relation); 222 | } 223 | 224 | @Override 225 | public int hashCode() { 226 | int hash = 0; 227 | if (id != null) { 228 | hash += id.hashCode(); 229 | } else { 230 | hash = 0; 231 | } 232 | return hash; 233 | } 234 | 235 | @Override 236 | public boolean equals(Object object) { 237 | if (!(object instanceof RelationType)) { 238 | return false; 239 | } 240 | RelationType other = (RelationType)object; 241 | if (!isNull(this.getForwardName()) && !isNull(other.getForwardName()) && 242 | this.getForwardName().name().equalsIgnoreCase( 243 | other.getForwardName().name()) && 244 | !isNull(this.getForwardName()) && 245 | !isNull(other.getBackwardName()) && 246 | this.getBackwardName().name(). 247 | equalsIgnoreCase(other.getBackwardName().name())) { 248 | return true; 249 | } 250 | if (!isNull(this.getBackwardName()) && 251 | !isNull(other.getBackwardName()) && 252 | this.getBackwardName().name(). 253 | equalsIgnoreCase(other.getBackwardName().name()) && 254 | !isNull(this.getBackwardName()) && 255 | !isNull(other.getForwardName()) && 256 | this.getForwardName().name().equalsIgnoreCase( 257 | other.getForwardName().name())) { 258 | return true; 259 | } 260 | 261 | String equalsRelations[] = {"has_colour#has_color#has_hue#" + 262 | "has_luminance#has_intensity#has_colour#has_color#has_hue#" + 263 | "has_luminance#has_intensity", 264 | "has_condition#has_natural_effect#has_anthropogenic_effect#" + 265 | "has_condition#has_natural_effect#has_anthropogenic_effect", 266 | "has_size#has_length#has_height#has_width#has_depth#has_size#" + 267 | "has_length#has_height#has_width#has_depth" 268 | }; 269 | 270 | for (String equalsRelation : equalsRelations) { 271 | if (this.getForwardName() != null && other.getForwardName() != null && 272 | this.getBackwardName() != null && 273 | other.getBackwardName() != null) { 274 | if ((equalsRelation.contains(this.getForwardName().name()) && 275 | (equalsRelation.contains(other.getForwardName().name()) || 276 | equalsRelation.contains(other.getBackwardName().name()))) || 277 | (equalsRelation.contains(this.getBackwardName().name()) && 278 | (equalsRelation.contains(other.getForwardName().name()) || 279 | equalsRelation.contains(other.getBackwardName().name())))) { 280 | return true; 281 | } 282 | } 283 | } 284 | 285 | if ((isNull(this.getId()) && !isNull(other.getId())) || 286 | (!isNull(this.getId()) && !this.getId().equals(other.getId()))) { 287 | return false; 288 | } 289 | if (isNull(this.getId()) && isNull(other.getId())) { 290 | return false; 291 | } 292 | 293 | return true; 294 | } 295 | 296 | @Override 297 | public String toString() { 298 | return "gr.csri.poeticon.praxicon.db.entities.RelationType[Id=" + id + 299 | "]"; 300 | } 301 | } 302 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/Relations.java: -------------------------------------------------------------------------------- 1 | package gr.csri.poeticon.praxicon.db.entities; 2 | 3 | import gr.csri.poeticon.praxicon.db.dao.RelationDao; 4 | import gr.csri.poeticon.praxicon.db.dao.RelationTypeDao; 5 | import gr.csri.poeticon.praxicon.db.dao.implSQL.RelationDaoImpl; 6 | import gr.csri.poeticon.praxicon.db.dao.implSQL.RelationTypeDaoImpl; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import static java.util.Objects.isNull; 10 | import javax.xml.bind.annotation.XmlAccessType; 11 | import javax.xml.bind.annotation.XmlAccessorType; 12 | import javax.xml.bind.annotation.XmlElement; 13 | import javax.xml.bind.annotation.XmlRootElement; 14 | 15 | /** 16 | * 17 | * @author dmavroeidis 18 | */ 19 | @XmlRootElement(name = "relations") 20 | @XmlAccessorType(XmlAccessType.FIELD) 21 | 22 | public class Relations { 23 | 24 | @XmlElement(name = "relation") 25 | List relations = new ArrayList<>(); 26 | 27 | public List getRelations() { 28 | return relations; 29 | } 30 | 31 | public void setRelations(List relations) { 32 | this.relations = relations; 33 | } 34 | 35 | public Relations() { 36 | relations = new ArrayList<>(); 37 | } 38 | 39 | /** 40 | * Stores all relations of the collection in the database updating 41 | * same name entries 42 | */ 43 | public void storeRelations() { 44 | if (!relations.isEmpty()) { 45 | RelationDao rDao = new RelationDaoImpl(); 46 | Relation newRelation; 47 | for (Relation relation : relations) { 48 | newRelation = storeRelation(relation); 49 | rDao.getEntityManager().clear(); 50 | if (!isNull(newRelation)) { 51 | System.out.println("Storing Relation: " + newRelation. 52 | toString()); 53 | } 54 | } 55 | } 56 | } 57 | 58 | public Relation storeRelation(Relation relation) { 59 | /* 60 | * Analyze relation: 61 | * 1. Get left and right argument and check if they exist in the DB. 62 | * 1.1. If it is a concept, find it. 63 | * 1.1.1. If the concept exists 64 | * 1.1.1.1. Get the concept from the DB. 65 | * 1.1.1.2. Get the relation argument from the DB. If it doesn't exist, 66 | * create it 67 | * 1.1.2. If the concept doesn't exist, store the concept in the DB, 68 | * create a relation argument with this concept and store that in 69 | * the DB also. 70 | * 1.2. If it is a relation set, find it and store it using 71 | * RelationSets.storeRelationSet 72 | * 2. Get relation type and check if it exists 73 | * 2.1. If it exists, merge it 74 | * 2.2. If it doesn't exist, persist it 75 | * 3. Now, check if the relation arguments are related 76 | * 3.1. If they are, don't do anything 77 | * 3.2. If they aren't, persist the relation 78 | */ 79 | RelationTypeDao rtDao = new RelationTypeDaoImpl(); 80 | RelationDao rDao = new RelationDaoImpl(); 81 | RelationArgument newLeftRelationArgument; 82 | RelationArgument newRightRelationArgument; 83 | RelationSet leftRelationSet; 84 | RelationSet rightRelationSet; 85 | RelationSet retrievedLeftRelationSet; 86 | RelationSet retrievedRightRelationSet; 87 | Concepts newConceptsObject = new Concepts(); 88 | RelationArguments newRelationArgumentsObject = new RelationArguments(); 89 | RelationSets newRelationSetsObject = new RelationSets(); 90 | Concept newLeftConcept; 91 | Concept newRightConcept; 92 | Concept leftConcept; 93 | Concept rightConcept; 94 | boolean isConcept; 95 | 96 | // 1.1. If it is a concept, find it. 97 | isConcept = relation.getLeftArgument().isConcept(); 98 | if (isConcept) { 99 | leftConcept = relation.getLeftArgument().getConcept(); 100 | newLeftConcept = newConceptsObject.storeConcept(leftConcept); 101 | newLeftRelationArgument = newRelationArgumentsObject. 102 | storeRelationArgument(new RelationArgument(newLeftConcept)); 103 | } else { 104 | leftRelationSet = relation.getLeftArgument(). 105 | getRelationSet(); 106 | retrievedLeftRelationSet = newRelationSetsObject.storeRelationSet( 107 | leftRelationSet); 108 | RelationArgument leftRelationArgument = new RelationArgument( 109 | retrievedLeftRelationSet); 110 | newLeftRelationArgument = newRelationArgumentsObject. 111 | storeRelationArgument(leftRelationArgument); 112 | } 113 | 114 | isConcept = relation.getRightArgument().isConcept(); 115 | if (isConcept) { 116 | rightConcept = relation.getRightArgument().getConcept(); 117 | newRightConcept = newConceptsObject.storeConcept(rightConcept); 118 | newRightRelationArgument = newRelationArgumentsObject. 119 | storeRelationArgument( 120 | new RelationArgument(newRightConcept)); 121 | } else { 122 | rightRelationSet = relation.getRightArgument(). 123 | getRelationSet(); 124 | retrievedRightRelationSet = newRelationSetsObject. 125 | storeRelationSet(rightRelationSet); 126 | RelationArgument rightRelationArgument = new RelationArgument( 127 | retrievedRightRelationSet); 128 | newRightRelationArgument = newRelationArgumentsObject. 129 | storeRelationArgument(rightRelationArgument); 130 | } 131 | 132 | // 2. Get relation type 133 | RelationType retrievedRelationType = rtDao. 134 | getRelationTypeByForwardName( 135 | relation.getRelationType().getForwardName()); 136 | RelationType relationType = new RelationType(); 137 | // 2.1 & 2.2 138 | if (!isNull(retrievedRelationType)) { 139 | rtDao.merge(retrievedRelationType); 140 | relationType = retrievedRelationType; 141 | } else { 142 | RelationType newRelationType = relation.getRelationType(); 143 | for (RelationType.RelationNameForward rt 144 | : RelationType.RelationNameForward.values()) { 145 | if (rt.equals(newRelationType.getForwardName())) { 146 | rtDao.persist(newRelationType); 147 | relationType = newRelationType; 148 | } 149 | } 150 | } 151 | Relation newRelation = new Relation(); 152 | // 3. Check if related 153 | boolean areRelated = rDao.areRelated(newLeftRelationArgument, 154 | newRightRelationArgument); 155 | // Create a new relation with new components 156 | newRelation.setLeftArgument(newLeftRelationArgument); 157 | newRelation.setRightArgument(newRightRelationArgument); 158 | newRelation.setRelationType(relationType); 159 | newRelation.setInferred(relation.getInferred()); 160 | newRelation.setLinguisticSupport( 161 | relation.getLinguisticallySupported()); 162 | if (!areRelated) { 163 | rDao.persist(newRelation); 164 | return newRelation; 165 | } else { 166 | Relation retrievedRelation = rDao.getRelation( 167 | newLeftRelationArgument, newRightRelationArgument, 168 | relationType.getForwardName()); 169 | // Check for existence 170 | if (!isNull(retrievedRelation)) { 171 | rDao.merge(retrievedRelation); 172 | return retrievedRelation; 173 | } else { 174 | rDao.persist(newRelation); 175 | return newRelation; 176 | } 177 | } 178 | } 179 | 180 | } 181 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/VisualRepresentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.entities; 6 | 7 | import gr.csri.poeticon.praxicon.Constants; 8 | import java.io.Serializable; 9 | import java.net.MalformedURLException; 10 | import java.net.URI; 11 | import java.net.URISyntaxException; 12 | import java.net.URL; 13 | import java.util.Objects; 14 | import static java.util.Objects.isNull; 15 | import javax.persistence.Column; 16 | import javax.persistence.Entity; 17 | import javax.persistence.EnumType; 18 | import javax.persistence.Enumerated; 19 | import javax.persistence.GeneratedValue; 20 | import javax.persistence.GenerationType; 21 | import javax.persistence.Id; 22 | import javax.persistence.Index; 23 | import javax.persistence.JoinColumn; 24 | import javax.persistence.ManyToOne; 25 | import javax.persistence.Table; 26 | import javax.validation.constraints.NotNull; 27 | import javax.xml.bind.annotation.XmlAccessType; 28 | import javax.xml.bind.annotation.XmlAccessorType; 29 | import javax.xml.bind.annotation.XmlTransient; 30 | import javax.xml.bind.annotation.XmlType; 31 | import org.apache.commons.lang.builder.EqualsBuilder; 32 | 33 | /** 34 | * 35 | * @author dmavroeidis 36 | * 37 | */ 38 | @XmlAccessorType(XmlAccessType.FIELD) 39 | @XmlType(name = "visual_representation", 40 | namespace = "http://www.csri.gr/visual_representation") 41 | @Entity 42 | @Table(name = "VisualRepresentations", 43 | indexes = { 44 | @Index(columnList = "Name")}//, 45 | // uniqueConstraints = { 46 | // @UniqueConstraint(columnNames = {"MediaType", "Name", "Source" , 47 | // "Uri" 48 | // }),} 49 | 50 | ) 51 | public class VisualRepresentation implements Serializable { 52 | 53 | public static enum MediaType { 54 | 55 | IMAGE, VIDEO; 56 | 57 | @Override 58 | public String toString() { 59 | return this.name(); 60 | } 61 | } 62 | 63 | private static final long serialVersionUID = 1L; 64 | @Id 65 | @XmlTransient 66 | @Column(name = "VisualRepresentationId") 67 | @GeneratedValue(strategy = GenerationType.IDENTITY) 68 | private Long id; 69 | 70 | @Column(name = "MediaType") 71 | @NotNull(message = "Media type must be specified.") 72 | @Enumerated(EnumType.STRING) 73 | private MediaType mediaType; 74 | 75 | @Column(name = "Name") 76 | private String name; 77 | 78 | @XmlTransient 79 | @ManyToOne 80 | private Concept concept; 81 | 82 | @XmlTransient 83 | @ManyToOne 84 | private RelationSet relationSet; 85 | 86 | @Column(name = "Source") 87 | private String source; 88 | 89 | @Column(name = "Uri", columnDefinition = "BLOB") 90 | @NotNull(message = "URI must be specified.") 91 | private URI uri; 92 | 93 | @Column(name = "Comment") 94 | private String comment; 95 | 96 | @XmlTransient 97 | @ManyToOne 98 | @JoinColumn(name = "MotoricRepresentation_motoricRepresentationId") 99 | private MotoricRepresentation motoricRepresentation; 100 | 101 | public VisualRepresentation(MediaType mediaType, String name) { 102 | this.mediaType = mediaType; 103 | this.name = name; 104 | } 105 | 106 | public VisualRepresentation() { 107 | } 108 | 109 | public Long getId() { 110 | return id; 111 | } 112 | 113 | public void setId(Long id) { 114 | this.id = id; 115 | } 116 | 117 | /** 118 | * @return the media type of this visual representation. 119 | */ 120 | public MediaType getMediaType() { 121 | return mediaType; 122 | } 123 | 124 | public void setMediaType(MediaType mediaType) { 125 | this.mediaType = mediaType; 126 | } 127 | 128 | /** 129 | * @return the concept connected to the visual representation. 130 | */ 131 | public Concept getConcept() { 132 | return concept; 133 | } 134 | 135 | public void setConcept(Concept concept) { 136 | this.concept = concept; 137 | } 138 | 139 | /** 140 | * @return the relation set connected to the visual representation. 141 | */ 142 | public RelationSet getRelationSet() { 143 | return relationSet; 144 | } 145 | 146 | public void setRelationSet(RelationSet relationSet) { 147 | this.relationSet = relationSet; 148 | } 149 | 150 | /** 151 | * @return the source of the visual representation. 152 | * This can be ImageNet, GoogleImages, etc. 153 | */ 154 | public String getSource() { 155 | return source; 156 | } 157 | 158 | public void setSource(String source) { 159 | this.source = source; 160 | } 161 | 162 | /** 163 | * @return the URI of the visual representation. Usually a URL or file path. 164 | */ 165 | public URI getUri() { 166 | return uri; 167 | } 168 | 169 | public void setUri(URI uri) { 170 | this.uri = uri; 171 | } 172 | 173 | public void setUri(String uri) throws URISyntaxException, 174 | MalformedURLException { 175 | String[] schemes = {"http", "https"}; 176 | URL url = null; 177 | try { 178 | url = new URL(uri); 179 | this.uri = url.toURI(); 180 | } catch (MalformedURLException em) { 181 | System.err.println("URL " + uri + " is malformed."); 182 | } catch (URISyntaxException eu) { 183 | System.err.println("URI syntax exception " + url); 184 | } 185 | } 186 | 187 | public String getName() { 188 | return name; 189 | } 190 | 191 | public void setName(String name) { 192 | this.name = name; 193 | } 194 | 195 | public String getRepresentationWithPath() { 196 | if (uri.toString().startsWith("http:")) { 197 | return uri.toString(); 198 | } 199 | if (uri.toString().startsWith("file:")) { 200 | return uri.toString(); 201 | } 202 | if (this.mediaType.equals(MediaType.IMAGE)) { 203 | return Constants.imagePath + uri.toString(); 204 | } else { 205 | return Constants.videoPath + uri.toString(); 206 | } 207 | } 208 | 209 | public String getComment() { 210 | return comment; 211 | } 212 | 213 | public void setComment(String comment) { 214 | this.comment = comment; 215 | } 216 | 217 | public MotoricRepresentation getMotoricRepresentation() { 218 | return motoricRepresentation; 219 | } 220 | 221 | public void setMotoricRepresentation( 222 | MotoricRepresentation motoricRepresentation) { 223 | this.motoricRepresentation = motoricRepresentation; 224 | } 225 | 226 | @Override 227 | public int hashCode() { 228 | int hash = 5; 229 | hash = 47 * hash + Objects.hashCode(this.mediaType); 230 | hash = 47 * hash + Objects.hashCode(this.name); 231 | hash = 47 * hash + Objects.hashCode(this.source); 232 | hash = 47 * hash + Objects.hashCode(this.uri); 233 | // hash = 47 * hash + Objects.hashCode(this.motoricRepresentation); 234 | return hash; 235 | } 236 | 237 | @Override 238 | /* 239 | * TODO: Create a realistic equals() method 240 | */ 241 | public boolean equals(Object obj) { 242 | if (obj == null) { 243 | return false; 244 | } 245 | if (getClass() != obj.getClass()) { 246 | return false; 247 | } 248 | final VisualRepresentation other = (VisualRepresentation)obj; 249 | EqualsBuilder eb = new EqualsBuilder(); 250 | eb.append(this.mediaType, other.getMediaType()); 251 | eb.append(this.name, other.getName()); 252 | eb.append(this.source, other.getSource()); 253 | eb.append(this.uri, other.getUri()); 254 | return eb.isEquals(); 255 | } 256 | 257 | @Override 258 | public String toString() { 259 | if (isNull(this.name) || this.name.equals("")) { 260 | return this.mediaType + "\\" + this.uri; 261 | } else { 262 | return this.name + "\\" + this.mediaType + "\\" + this.uri; 263 | } 264 | } 265 | } 266 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/comparators/LexicalEntryComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.entities.comparators; 6 | 7 | import gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation; 8 | import java.util.Comparator; 9 | 10 | /** 11 | * 12 | * @author Erevodifwntas 13 | */ 14 | public class LexicalEntryComparator implements 15 | Comparator { 16 | 17 | /** 18 | * Compares languages of two Language representations 19 | * 20 | * @param a the first Language representation 21 | * @param b the second Language representation 22 | * 23 | * @return integer result of compare 24 | */ 25 | @Override 26 | public int compare(LanguageRepresentation a, LanguageRepresentation b) { 27 | return a.getLanguage().name(). 28 | compareToIgnoreCase(b.getLanguage().name()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/comparators/MotoricEntryComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.entities.comparators; 6 | 7 | import gr.csri.poeticon.praxicon.db.entities.MotoricRepresentation; 8 | import java.util.Comparator; 9 | 10 | /** 11 | * 12 | * @author Erevodifwntas 13 | */ 14 | public class MotoricEntryComparator implements 15 | Comparator { 16 | 17 | /** 18 | * NOT IMPLEMENTED YET 19 | * 20 | * @param a the first MotoricRepresentation 21 | * @param b the second MotoricRepresentation 22 | * 23 | * @return integer result of compare (NOW 1) 24 | */ 25 | @Override 26 | public int compare(MotoricRepresentation a, MotoricRepresentation b) { 27 | //To be Implemented!!! 28 | return 1; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/comparators/VisualEntryComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.entities.comparators; 6 | 7 | import gr.csri.poeticon.praxicon.db.entities.VisualRepresentation; 8 | import java.util.Comparator; 9 | 10 | /** 11 | * 12 | * @author Erevodifwntas 13 | */ 14 | public class VisualEntryComparator implements Comparator { 15 | 16 | /** 17 | * NOT IMPLEMENTED YET 18 | * 19 | * @param a the first VisualRepresentation 20 | * @param b the second VisualRepresentation 21 | * 22 | * @return integer result of compare (NOW 1) 23 | */ 24 | @Override 25 | public int compare(VisualRepresentation a, VisualRepresentation b) { 26 | //To be Implemented!!! 27 | return 1; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/jaxb.index: -------------------------------------------------------------------------------- 1 | CollectionOfObjects 2 | Concept 3 | Concepts 4 | LanguageRepresentation 5 | MotoricRepresentation 6 | Relation 7 | Relations 8 | RelationSet 9 | RelationSets 10 | RelationType 11 | VisualRepresentation -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/listeners/ConceptListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.entities.listeners; 6 | 7 | /** 8 | * 9 | * @author Erevodifwntas 10 | */ 11 | public class ConceptListener { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/package-info.java: -------------------------------------------------------------------------------- 1 | @XmlAccessorType(XmlAccessType.FIELD) 2 | package gr.csri.poeticon.praxicon.db.entities; 3 | 4 | import javax.xml.bind.annotation.XmlAccessType; 5 | import javax.xml.bind.annotation.XmlAccessorType; 6 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/validators/ConceptValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.entities.validators; 6 | 7 | import gr.csri.poeticon.praxicon.db.entities.Concept; 8 | import gr.csri.poeticon.praxicon.db.entities.Concept.Status; 9 | import gr.csri.poeticon.praxicon.db.entities.Concept.UniqueInstance; 10 | import javax.validation.ConstraintValidator; 11 | import javax.validation.ConstraintValidatorContext; 12 | 13 | /** 14 | * 15 | * @author dmavroeidis 16 | */ 17 | public class ConceptValidator implements 18 | ConstraintValidator { 19 | 20 | private boolean isValid; 21 | 22 | @Override 23 | public void initialize(ConstantConcepts constraintAnnotation) { 24 | this.isValid = constraintAnnotation.value(); 25 | } 26 | 27 | @Override 28 | public boolean isValid(Concept value, ConstraintValidatorContext context) { 29 | if ((value.getStatus() == Status.CONSTANT) && 30 | (value.getUniqueInstance() == UniqueInstance.YES)) { 31 | return true; 32 | } else { 33 | return false; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/gr/csri/poeticon/praxicon/db/entities/validators/ConstantConcepts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package gr.csri.poeticon.praxicon.db.entities.validators; 6 | 7 | import java.lang.annotation.Documented; 8 | import java.lang.annotation.ElementType; 9 | import java.lang.annotation.Retention; 10 | import java.lang.annotation.RetentionPolicy; 11 | import java.lang.annotation.Target; 12 | import javax.validation.Constraint; 13 | import javax.validation.Payload; 14 | 15 | /** 16 | * 17 | * @author dmavroeidis 18 | */ 19 | @Retention(RetentionPolicy.RUNTIME) 20 | @Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD}) 21 | @Constraint(validatedBy = ConceptValidator.class) 22 | @Documented 23 | public @interface ConstantConcepts { 24 | 25 | String message() default "Constant Concept constraint has been violated"; 26 | 27 | Class[] groups() default {}; 28 | 29 | Class[] payload() default {}; 30 | 31 | boolean value(); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/persistence.xml.sample: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | org.hibernate.jpa.HibernatePersistenceProvider 5 | gr.csri.poeticon.praxicon.db.entities.Concept 6 | gr.csri.poeticon.praxicon.db.entities.Concept_LanguageRepresentation 7 | gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation 8 | gr.csri.poeticon.praxicon.db.entities.MotoricRepresentation 9 | gr.csri.poeticon.praxicon.db.entities.OntologicalDomain 10 | gr.csri.poeticon.praxicon.db.entities.Relation 11 | gr.csri.poeticon.praxicon.db.entities.RelationArgument 12 | gr.csri.poeticon.praxicon.db.entities.RelationSet 13 | gr.csri.poeticon.praxicon.db.entities.RelationSet_Relation 14 | gr.csri.poeticon.praxicon.db.entities.RelationType 15 | gr.csri.poeticon.praxicon.db.entities.VisualRepresentation 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | org.hibernate.jpa.HibernatePersistenceProvider 25 | gr.csri.poeticon.praxicon.db.entities.Concept 26 | gr.csri.poeticon.praxicon.db.entities.Concept_LanguageRepresentation 27 | gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation 28 | gr.csri.poeticon.praxicon.db.entities.MotoricRepresentation 29 | gr.csri.poeticon.praxicon.db.entities.OntologicalDomain 30 | gr.csri.poeticon.praxicon.db.entities.Relation 31 | gr.csri.poeticon.praxicon.db.entities.RelationArgument 32 | gr.csri.poeticon.praxicon.db.entities.RelationSet 33 | gr.csri.poeticon.praxicon.db.entities.RelationSet_Relation 34 | gr.csri.poeticon.praxicon.db.entities.RelationType 35 | gr.csri.poeticon.praxicon.db.entities.VisualRepresentation 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | org.hibernate.jpa.HibernatePersistenceProvider 5 | gr.csri.poeticon.praxicon.db.entities.Compositionality 6 | gr.csri.poeticon.praxicon.db.entities.Concept 7 | gr.csri.poeticon.praxicon.db.entities.Concept_LanguageRepresentation 8 | gr.csri.poeticon.praxicon.db.entities.Constituent 9 | gr.csri.poeticon.praxicon.db.entities.LanguageRepresentation 10 | gr.csri.poeticon.praxicon.db.entities.MotoricRepresentation 11 | gr.csri.poeticon.praxicon.db.entities.Relation 12 | gr.csri.poeticon.praxicon.db.entities.RelationArgument 13 | gr.csri.poeticon.praxicon.db.entities.RelationSet 14 | gr.csri.poeticon.praxicon.db.entities.RelationSet_Relation 15 | gr.csri.poeticon.praxicon.db.entities.RelationType 16 | gr.csri.poeticon.praxicon.db.entities.Verbalization 17 | gr.csri.poeticon.praxicon.db.entities.VisualRepresentation 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /templates/jaxb.xdt: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /templates/xmlHelpFile.xdt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Praxicon's XML Tags Index 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
Praxicon's XML Tags Index
31 | 32 | -------------------------------------------------------------------------------- /xsd/compositionality.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /xsd/concept.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /xsd/constituent.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /xsd/intersection_of_relation_chains.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /xsd/language_representation.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /xsd/motoric_representation.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /xsd/relation.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /xsd/relation_chain.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /xsd/relation_type.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /xsd/relationchain_relation.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /xsd/verbalization.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /xsd/visual_representation.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | --------------------------------------------------------------------------------