From 3a97cebbcfd49d817d3935e187616b06144f4b85 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 31 Aug 2017 07:07:03 +0300 Subject: [PATCH 1/5] updating negative rules --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e07eeed..83632bb 100644 --- a/README.md +++ b/README.md @@ -72,13 +72,16 @@ aml:conf uri:path "C:/HeterogeneityExampleData/AutomationML/Single-Heterogeneity/M2/Testbeds-2/"; uri:experimentFolder "E:/ExperimentsToKCAP/Experiment1/run -1/"; sto:Standard "aml"; - ontosec:Training "false"; + ontosec:Training "false"; + uri:NegativeRules "true"; uri:URI "C:/Experiments/SemCPS-/resources/". ``` Please note: ``` uri:path refers to Heterogeneity path -uri:URI refers to the ontology path +uri:URI refers to the ontology path +Negative rules true to user orignal. +false to use emulation. ``` Just give path of AML heterogenity and folders will be created automatically. From a7901e0520c4e406781d5c1dc22990f124047491 Mon Sep 17 00:00:00 2001 From: igrangel Date: Thu, 31 Aug 2017 11:47:35 +0200 Subject: [PATCH 2/5] more cleaning --- src/main/java/industryStandard/AML.java | 39 ++++++++++++++----- .../{XmlParser.java => XMLParser.java} | 8 ++-- 2 files changed, 33 insertions(+), 14 deletions(-) rename src/main/java/integration/{XmlParser.java => XMLParser.java} (99%) diff --git a/src/main/java/industryStandard/AML.java b/src/main/java/industryStandard/AML.java index 1783c60..6fbe920 100644 --- a/src/main/java/industryStandard/AML.java +++ b/src/main/java/industryStandard/AML.java @@ -10,17 +10,20 @@ /** * * @author Irlan Grangel - * - * Represents the AutomationML Standard as an RDF graph + * Represents the AutomationML(AML) Standard as an RDF Knowledge graph */ public class AML extends IndustryStandards { + /** + * Constructs the AML object + * @param model RDF Jena model containing all the AML facts in RDF + * @param newNumber number to identify the AML document + */ public AML(Model model, int newNumber) { super(model, newNumber); } public AML() { - // TODO Auto-generated constructor stub } public void setModel(Model model) { @@ -70,11 +73,12 @@ public void addsDataforAML() throws FileNotFoundException { addGenericObject("hasRefSemantic", "hasCorrespondingAttributePath"); } + /*** + * Eclass part starts here. + * TODO refactoring and functions only for test + * purpose now + */ private void eClassCheck() { - /*** - * Eclass part starts here. TODO refactoring and functions only for test - * purpose now - */ if (object.isLiteral()) { if (checkEclass(object)) { StmtIterator stmts = model.listStatements(subject.asResource(), null, @@ -109,6 +113,9 @@ private void eClassCheck() { } } + /** + * TODO to write comments + */ private void hasIdentifier() { // RefSemantic part starts here @@ -119,6 +126,9 @@ private void hasIdentifier() { } } + /** + * TODO to write comments + */ private void hasAttribute() { if (predicate.asNode().getLocalName().equals("hasAttribute")) { // gets all classes which hasAttribute relation @@ -127,6 +137,9 @@ private void hasAttribute() { } } + /** + * TODO to write comments + */ private void hasAttributeValue() { if (predicate.asNode().getLocalName().equals("hasAttributeValue")) { if (!checkEclass(object)) { @@ -137,6 +150,9 @@ private void hasAttributeValue() { } + /** + * TODO to write comments + */ private void addHasType() { if (predicate.asNode().getLocalName().equals("type")) { if (number != 3) @@ -146,6 +162,9 @@ private void addHasType() { } + /** + * TODO to write comments + */ private void addDomainRange() { // Adds domain and range if (predicate.asNode().getLocalName().equals("domain") @@ -162,6 +181,9 @@ private void addDomainRange() { } } + /** + * TODO to write comments + */ private void hasAttributeName() { if (predicate.asNode().getLocalName().equals("hasAttributeName")) { if (!checkEclass(object)) { @@ -178,9 +200,8 @@ private void hasAttributeName() { } /** - * checks if its elcass then ignore it because we only need values with + * checks if its eClass then ignore it because we only need values with * object which can be unique. - * * @param object * @return */ diff --git a/src/main/java/integration/XmlParser.java b/src/main/java/integration/XMLParser.java similarity index 99% rename from src/main/java/integration/XmlParser.java rename to src/main/java/integration/XMLParser.java index 145e3ce..7df230a 100644 --- a/src/main/java/integration/XmlParser.java +++ b/src/main/java/integration/XMLParser.java @@ -32,9 +32,9 @@ /** * @author omar - * + * TODO to write comments */ -public class XmlParser { +public class XMLParser { private static XPathFactory xpf; private static XPath xpath; @@ -44,7 +44,7 @@ public class XmlParser { /* * Constructor initializes */ - public XmlParser() { + public XMLParser() { integrationNodes = new ArrayList(); seedNodes = new ArrayList(); xpf = XPathFactory.newInstance(); @@ -459,7 +459,6 @@ void finalizeIntegration(Document integration, String file) throws TransformerFa * @param integration * @throws XPathExpressionException */ - void setNodeValues(Document seed, Document integration) throws XPathExpressionException { seedNodes = new ArrayList(); @@ -482,7 +481,6 @@ void setNodeValues(Document seed, Document integration) throws XPathExpressionEx * @param doc * @return */ - public static ArrayList getAllNodes(Document doc) { ArrayList node = new ArrayList(); From 7619a6d0c88f6b6fac03ff4bd037b73540215a9f Mon Sep 17 00:00:00 2001 From: igrangel Date: Thu, 31 Aug 2017 12:07:26 +0200 Subject: [PATCH 3/5] following naming patterns --- src/main/java/pslApproach/KGAlignment.groovy | 445 ++++++++++--------- 1 file changed, 223 insertions(+), 222 deletions(-) diff --git a/src/main/java/pslApproach/KGAlignment.groovy b/src/main/java/pslApproach/KGAlignment.groovy index 0592763..ba8197e 100644 --- a/src/main/java/pslApproach/KGAlignment.groovy +++ b/src/main/java/pslApproach/KGAlignment.groovy @@ -66,7 +66,7 @@ public class DocumentAligment defineOntoRules() defineSetRules() if (util.ConfigManager.getNegativeRules().equals("true")){ - defineNotSimilarRules() + defineNotSimilarRules() } setUpData() runInference() @@ -101,19 +101,19 @@ public class DocumentAligment model.add predicate: "hasAttribute" , types: [ArgumentType.UniqueID, ArgumentType.UniqueID] model.add predicate: "hasInternalElement" , types: [ArgumentType.UniqueID, ArgumentType.UniqueID] - + model.add predicate: "hasInstanceHierarchy" , types: [ArgumentType.UniqueID, ArgumentType.UniqueID] - + model.add predicate: "hasRefSemantic" , types: [ArgumentType.UniqueID, ArgumentType.String] model.add predicate: "hasInternalElementID" , types: [ArgumentType.UniqueID, ArgumentType.String] model.add predicate: "hasInstanceHierarchyID" , types: [ArgumentType.UniqueID, ArgumentType.String] - + model.add predicate: "hasExternalInterfaceID" , types: [ArgumentType.UniqueID, ArgumentType.String] - + model.add predicate: "hasAttributeID" , types: [ArgumentType.UniqueID, ArgumentType.String] - + model.add predicate: "hasInternalLink" , types: [ArgumentType.UniqueID, ArgumentType.String] model.add predicate: "hasEClassVersion" , types: [ArgumentType.UniqueID, ArgumentType.String] @@ -127,55 +127,61 @@ public class DocumentAligment model.add predicate: "similarType" , types: [ArgumentType.UniqueID, ArgumentType.UniqueID] model.add predicate: "eval", types: [ArgumentType.String, ArgumentType.String] - + model.add predicate: "hasRoleClassLib" , types: [ArgumentType.UniqueID, ArgumentType.UniqueID] - + model.add predicate: "hasRoleClass" , types: [ArgumentType.UniqueID, ArgumentType.UniqueID] model.add predicate: "hasInterfaceClass" , types: [ArgumentType.UniqueID, ArgumentType.UniqueID] model.add predicate: "hasSystemUnitClass" , types: [ArgumentType.UniqueID, ArgumentType.UniqueID] - + model.add predicate: "hasAttributeName" , types: [ArgumentType.UniqueID, ArgumentType.String] - + model.add predicate: "hasInstanceHierarchyAttributeName" , types: [ArgumentType.UniqueID, ArgumentType.String] - + model.add predicate: "hasInterfaceClassAttributeName" , types: [ArgumentType.UniqueID, ArgumentType.String] - + model.add predicate: "hasInternalElementAttributeName" , types: [ArgumentType.UniqueID, ArgumentType.String] - + model.add predicate: "hasSystemUnitClassAttributeName" , types: [ArgumentType.UniqueID, ArgumentType.String] model.add predicate: "hasSystemUnitClassLibAttributeName" , types: [ArgumentType.UniqueID, ArgumentType.String] - + model.add predicate: "hasRoleClassAttributeName" , types: [ArgumentType.UniqueID, ArgumentType.String] - + model.add predicate: "hasRoleClassLibAttributeName" , types: [ArgumentType.UniqueID, ArgumentType.String] - + model.add predicate: "hasInternalLinkAttributeName" , types: [ArgumentType.UniqueID, ArgumentType.String] - + model.add predicate: "hasAttributeValue" , types: [ArgumentType.UniqueID, ArgumentType.String] - + model.add predicate: "hasCAEXFile" , types: [ArgumentType.UniqueID, ArgumentType.UniqueID] - + model.add predicate: "hasExternalReference" , types: [ArgumentType.UniqueID, ArgumentType.String] model.add predicate: "hasType" , types: [ArgumentType.UniqueID, ArgumentType.UniqueID] - + model.add predicate: "notSimilar" , types: [ArgumentType.UniqueID, ArgumentType.UniqueID] - - + + } + /** + * TODO to write comments + */ public void defineFunctions() { try{ - model.add function: "similarValue" , implementation: new DiceSimilarity() + model.add function: "similarValue" , implementation: new DiceSimilarity() }catch(Exception e){ - + } } + /** + * TODO to write comments + */ public void defineRules() { @@ -195,56 +201,56 @@ public class DocumentAligment // Two AML Attributes are the same if they have the same name model.add rule : (hasAttributeName(A,Z) & hasAttributeName(B,W) & similarValue(Z,W) & - hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B), weight : 1 + hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B), weight : 1 // Two InterfaceClass are the same if they have the same name model.add rule : (hasInterfaceClassAttributeName(A,Z) & hasInterfaceClassAttributeName(B,W) & similarValue(Z,W) & - hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 4 + hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 4 // Two InstanceHierarichy are the same if they have the same name model.add rule : (hasInstanceHierarchyAttributeName(A,Z) & hasInstanceHierarchyAttributeName(B,W) & similarValue(Z,W) & - hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 4 + hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 4 // Two InternalLink are the same if they have the same name model.add rule : (hasInternalLinkAttributeName(A,Z) & hasInternalLinkAttributeName(B,W) & similarValue(Z,W) & - hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 4 + hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 4 // Two InternalElement are the same if they have the same name model.add rule : (hasInternalElementAttributeName(A,Z) & hasInternalElementAttributeName(B,W) & similarValue(Z,W) & - hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 1 + hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 1 // Two RoleClassLib are the same if they have the same name model.add rule : (hasRoleClassLibAttributeName(A,Z) & hasRoleClassLibAttributeName(B,W) & similarValue(Z,W) & - hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 4 + hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 4 // Two RoleClass are the same if they have the same name model.add rule : (hasRoleClassAttributeName(A,Z) & hasRoleClassAttributeName(B,W) & similarValue(Z,W) & - hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 4 + hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 4 // Two SystemUnitClassLib are the same if they have the same name model.add rule : (hasSystemUnitClassLibAttributeName(A,Z) & hasSystemUnitClassLibAttributeName(B,W) & similarValue(Z,W) & - hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 4 + hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 4 // Two SystemUnitClass are the same if they have the same name model.add rule : (hasSystemUnitClassAttributeName(A,Z) & hasSystemUnitClassAttributeName(B,W) & similarValue(Z,W) & - hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 4 + hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 4 // Two AML Attributes are the same if they have the same values model.add rule : (hasAttributeValue(A,Z) & hasAttributeValue(B,W) & similarValue(Z,W) & - hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 1 + hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 1 // Two AMl InternalElement are the same if they share the same ID model.add rule : (hasInternalElementID(A,Z) & hasInternalElementID(B,W) & similarValue(Z,W) &hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 10 - + // Two AMl ExternalElement are the same if they share the same ID model.add rule : (hasExternalInterfaceID(A,Z) & hasExternalInterfaceID(B,W) & similarValue(Z,W) &hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , weight : 10 - + // Two AMl InstanceHierarchy are the same if they share the same ID model.add rule : (hasInstanceHierarchyID(A,Z) & hasInstanceHierarchyID(B,W) & similarValue(Z,W) &hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(A,B) , @@ -287,12 +293,12 @@ public class DocumentAligment // prior model.add rule : ~similar(A,B), weight: 1 } - + /** * Rules for not similar */ public void defineNotSimilarRules(){ - + // Two AML CAEX files are the not same if they have the not same path model.add rule : (hasCAEXFile(A,X) & hasCAEXFile(B,Y) & hasExternalReference(X,Z) & hasExternalReference(Y,W) & ~similarValue(Z,W) & hasDocument(A,O1) & hasDocument(B,O2) & @@ -307,34 +313,34 @@ public class DocumentAligment model.add rule : (hasAttributeName(A,Z) & hasAttributeName(B,W) & ~similarValue(Z,W) & hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> ~similar(A,B), weight : 10 - + // Two AMl hasAttributes are the not same if they share the not same ID model.add rule : (hasAttributeID(A,Z) & hasAttributeID(B,W) & ~similarValue(Z,W) & hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> notSimilar(A,B) ,weight : 10 - + // Two InterfaceClass are not the same if they have the same name model.add rule : (hasInterfaceClassAttributeName(A,Z) & hasInterfaceClassAttributeName(B,W) & ~similarValue(Z,W) & - hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> notSimilar(A,B) , weight : 4 + hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> notSimilar(A,B) , weight : 4 // Two InternalElement are not the same if they have the same name model.add rule : (hasInternalElementAttributeName(A,Z) & hasInternalElementAttributeName(B,W) & ~similarValue(Z,W) & - hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> notSimilar(A,B) , weight : 4 + hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> notSimilar(A,B) , weight : 4 // Two RoleClass are not the same if they have the same name model.add rule : (hasRoleClassAttributeName(A,Z) & hasRoleClassAttributeName(B,W) & ~similarValue(Z,W) & - hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> notsimilar(A,B) , weight : 4 + hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> notsimilar(A,B) , weight : 4 // Two RoleClassLib are not the same if they have the same name model.add rule : (hasRoleClassLibAttributeName(A,Z) & hasRoleClassLibAttributeName(B,W) & ~similarValue(Z,W) & - hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> notsimilar(A,B) , weight : 4 + hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> notsimilar(A,B) , weight : 4 // Two SystemUnitClassLib are the same if they have the same name model.add rule : (hasSystemUnitClassLibAttributeName(A,Z) & hasSystemUnitClassLibAttributeName(B,W) & ~similarValue(Z,W) & - hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> notSimilar(A,B) , weight : 4 + hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> notSimilar(A,B) , weight : 4 // Two SystemUnitClass are not the same if they have the same name model.add rule : (hasSystemUnitClassAttributeName(A,Z) & hasSystemUnitClassAttributeName(B,W) & ~similarValue(Z,W) & - hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> notSimilar(A,B) , weight : 4 + hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> notSimilar(A,B) , weight : 4 // Two AML Attributes are the not same if they have the not same values model.add rule : (hasAttribute(A,X) & hasAttribute(B,Y) & hasAttributeValue(A,Z) & @@ -351,7 +357,7 @@ public class DocumentAligment & hasInternalLink(Z,C) & hasInternalElementID(B,D) & ~similarValue(C,D) & hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> notSimilar(A,B) , weight : 10 - + // Two Roles Class are not same if its eclass,IRDI and classification class are the same model.add rule :( hasRoleClass(A1,B1) & hasRoleClass(A2,B2)& hasEClassIRDI(B1,Z) & hasEClassIRDI(B2,W) & ~similarValue(Z,W) & hasRoleClass(A1,C1) & hasRoleClass(A2,D2) @@ -395,9 +401,9 @@ public class DocumentAligment ~similarValue(Z,W) &hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> notSimilar(A,B) , weight : 4 - + } - + /** * Predicates for set or or collective inference */ @@ -405,62 +411,61 @@ public class DocumentAligment model.add predicate: "setSimilar" , types: [ArgumentType.UniqueID] model.add predicate: "setNotSimilar" , types: [ArgumentType.UniqueID, ArgumentType.UniqueID] model.add setcomparison: "similarAttributes", using: SetComparison.Equality, on : setNotSimilar - } - + /** * Rules for sets, or collective inference */ public void defineSetRules(){ - + } - - + + /** * Defines typical ontology predicates */ public void defineOntoPredicates(){ model.add predicate: "subclass", types: [ArgumentType.UniqueID, ArgumentType.UniqueID] - + model.add predicate: "hasDomain", types: [ArgumentType.UniqueID, ArgumentType.UniqueID] - + model.add predicate: "hasRange", types: [ArgumentType.UniqueID, ArgumentType.UniqueID] - + model.add predicate: "fromOntology", types: [ArgumentType.UniqueID, ArgumentType.UniqueID] } - + /** * Defines basic ontology rules */ public void defineOntoRules(){ - + model.add rule : (hasDomain(R,A) & hasDomain(T,B) & similar(A,B) & - hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(R,T), weight : 2; - + hasDocument(A,O1) & hasDocument(B,O2) & (O1-O2)) >> similar(R,T), weight : 2; + model.add rule : (hasRange(R,A) & hasRange(T,B) & similar(A,B) & hasDocument(A,O1) & - hasDocument(B,O2) & (O1-O2)) >> similar(R,T), weight : 2; - + hasDocument(B,O2) & (O1-O2)) >> similar(R,T), weight : 2; + model.add rule : (hasDomain(R,A) & hasDomain(T,B) & similar(R,T) & hasDocument(A,O1) & - hasDocument(B,O2) & (O1-O2)) >> similar(A,B), weight : 2; - + hasDocument(B,O2) & (O1-O2)) >> similar(A,B), weight : 2; + model.add rule : (hasRange(R,A) & hasRange(T,B) & similar(R,T) & hasDocument(A,O1) & - hasDocument(B,O2) & (O1-O2)) >> similar(A,B), weight : 2; - + hasDocument(B,O2) & (O1-O2)) >> similar(A,B), weight : 2; + GroundTerm classID = data.getUniqueID("class"); model.add rule : (similar(A,B) & hasType(A, classID) & hasType(B, classID) & subclass(A, S1) - & subclass(B, S2)& hasDocument(A,O1) & hasDocument(B,O2) & - (O1-O2)) >> similar(S1, S2), weight: 3; + & subclass(B, S2)& hasDocument(A,O1) & hasDocument(B,O2) & + (O1-O2)) >> similar(S1, S2), weight: 3; } /** - * + * TODO to write comments */ public void setUpData() { - /* Loads data */ + // Loads data dir = 'data' + java.io.File.separator + 'document' + java.io.File.separator - /////////////////////////// train setup ////////////////////////////////// + // train setup testDir = util.ConfigManager.getFilePath() + "PSL/test/" trainDir = util.ConfigManager.getFilePath() + "PSL/train/" @@ -469,7 +474,7 @@ public class DocumentAligment Partition trainPredictions = new Partition(1) Partition truth = new Partition(2) Partition other = new Partition(7) - + if(util.ConfigManager.getExecutionMethod() == "true"){ createFiles(trainDir + "similar.txt") @@ -507,7 +512,7 @@ public class DocumentAligment hasSystemUnitClassLibAttributeName, hasExternalInterfaceID, hasInternalLinkAttributeName - ] + ] ){ createFiles(trainDir + p.getName().toLowerCase() + ".txt") def insert = data.getInserter(p, trainObservations) @@ -518,41 +523,41 @@ public class DocumentAligment InserterUtils.loadDelimitedDataTruth(insert, trainDir + "similar.txt") trainDB = data.getDatabase(trainPredictions, [ - hasDocument, - hasAttribute, - hasRefSemantic, - hasInternalElementID, - hasAttributeID, - hasInternalLink, - hasEClassVersion, - hasEClassClassificationClass, - hasEClassIRDI, - hasRoleClass, - hasInternalElement, - hasSystemUnitClass, - hasInterfaceClass, - hasAttributeValue, - hasAttributeName, - hasInterfaceClassAttributeName, - hasInternalElementAttributeName, - hasRoleClassAttributeName, - hasSystemUnitClassAttributeName, - hasExternalReference, - hasCAEXFile, - hasInstanceHierarchyID, - hasInstanceHierarchy, - hasDomain, - hasRange, - hasType, - hasInstanceHierarchyAttributeName, - hasRoleClassLib, - hasRoleClassLibAttributeName, - hasSystemUnitClassLibAttributeName, - hasExternalInterfaceID, - hasInternalLinkAttributeName + hasDocument, + hasAttribute, + hasRefSemantic, + hasInternalElementID, + hasAttributeID, + hasInternalLink, + hasEClassVersion, + hasEClassClassificationClass, + hasEClassIRDI, + hasRoleClass, + hasInternalElement, + hasSystemUnitClass, + hasInterfaceClass, + hasAttributeValue, + hasAttributeName, + hasInterfaceClassAttributeName, + hasInternalElementAttributeName, + hasRoleClassAttributeName, + hasSystemUnitClassAttributeName, + hasExternalReference, + hasCAEXFile, + hasInstanceHierarchyID, + hasInstanceHierarchy, + hasDomain, + hasRange, + hasType, + hasInstanceHierarchyAttributeName, + hasRoleClassLib, + hasRoleClassLibAttributeName, + hasSystemUnitClassLibAttributeName, + hasExternalInterfaceID, + hasInternalLinkAttributeName ] as Set, trainObservations) - + populateSimilar(trainDB) truthDB = data.getDatabase(truth, [similar] as Set) @@ -566,7 +571,7 @@ public class DocumentAligment println "after training" + model } - /////////////////////////// test setup ////////////////////////////////// + // test setup Partition testObservations = new Partition(3) Partition testPredictions = new Partition(4) @@ -604,15 +609,15 @@ public class DocumentAligment hasSystemUnitClassLibAttributeName, hasExternalInterfaceID, hasInternalLinkAttributeName - - ]) + + ]) { createFiles(testDir + p.getName().toLowerCase() + ".txt") } createFiles(testDir + "similar.txt") createFiles(testDir + "similarwithConfidence.txt") createFiles(testDir + "GoldStandard.txt") - + for (Predicate p : [ hasDocument, hasAttribute, @@ -646,15 +651,15 @@ public class DocumentAligment hasSystemUnitClassLibAttributeName, hasExternalInterfaceID, hasInternalLinkAttributeName - ]) + ]) { - + def insert = data.getInserter(p, testObservations) InserterUtils.loadDelimitedData(insert, testDir + p.getName().toLowerCase() + ".txt") } - + testDB = data.getDatabase(testPredictions, [ hasDocument, hasAttribute, @@ -688,28 +693,38 @@ public class DocumentAligment hasSystemUnitClassLibAttributeName, hasExternalInterfaceID, hasInternalLinkAttributeName - + ] as Set, testObservations) populateSimilar(testDB) } + /** + * TODO to write comments + * @param testDir + */ public void createFiles(String testDir){ - - def dataFile = new File(testDir) + def dataFile = new File(testDir) if(!dataFile.exists()){ dataFile.createNewFile() } } + /** + * TODO to write comments + * @param matchResult + * @param symResult + * @return + */ int removeSymetric(File matchResult,String symResult){ - def flag=0 + def flag = 0 def lineNo = 1 def line - matchResult.withReader{ reader -> + matchResult.withReader { reader -> while ((line = reader.readLine())!=null) { - if(line.replace("\t","").replace(" ","").contains(symResult.replace("\t","").replace(" ",""))){ - return flag=1 + if(line.replace("\t","").replace(" ","") + .contains(symResult.replace("\t","").replace(" ",""))){ + return flag = 1 } lineNo++ } @@ -718,110 +733,104 @@ public class DocumentAligment } /** - * Function check if negative values have more confidence or not. + * Checks if negative values have more confidence or not. * @param confResult * @param symResult * @param value - * @return + * @return TODO to write what returns */ - int checkConfidence(File confResult,String symResult,double value){ - def flag=0 + int checkConfidence(File confResult, String symResult, double value){ + def flag = 0 def lineNo = 1 def line confResult.withReader{ reader -> - while ((line = reader.readLine())!=null) { + while ((line = reader.readLine()) != null) { if(line.replace("\t","").contains(symResult.replace("\t",""))){ - String temp=line.replace(symResult,"").trim(); + String temp = line.replace(symResult,"").trim(); try{ - double trueValue = temp.toDouble() - if(trueValue>value){ - return flag=1; - } - }catch(Exception e){ - - } - + double trueValue = temp.toDouble() + if(trueValue > value){ + return flag = 1; + } + }catch(Exception e){ + // TODO to handle this exception + } } - lineNo++ } } return flag } -/** - * Adds rules explaination - * @param predicate - * @param filename - */ - + /** + * Adds rules explanation + * @param predicate + * @param filename + */ public void ruleExplaination(Predicate predicate,String filename){ - - def matchResult = new File(testDir+"Precision/"+filename) + + def matchResult = new File(testDir + "Precision/" + filename) matchResult.write('') - - + for (GroundAtom atom : Queries.getAllAtoms(testDB, predicate)){ - Iterator igk = atom.getRegisteredGroundKernels().iterator(); + Iterator igk = atom.getRegisteredGroundKernels().iterator(); while(igk.hasNext()) { - Iterator iga = igk.next().getAtoms().iterator(); - while (iga.hasNext()) { //gets predicate - GroundAtom gatom = iga.next(); - if(gatom.getValue()>0.7){ - matchResult.append(gatom.getRegisteredGroundKernels() + "\t" - + gatom.getValue() + "\n \n") - } - }}} - + Iterator iga = igk.next().getAtoms().iterator(); + while (iga.hasNext()) { //gets predicate + GroundAtom gatom = iga.next(); + if(gatom.getValue() > 0.7){ + matchResult.append(gatom.getRegisteredGroundKernels() + "\t" + + gatom.getValue() + "\n \n") + } + }}} } - - - + + + /** + * TODO to write comments + */ public void runInference(){ - /////////////////////////// test inference ////////////////////////////////// println "INFERRING..." - MPEInference inference = new MPEInference(model, testDB, config) + MPEInference inference = new MPEInference(model, testDB, config) inference.mpeInference() inference.close() - + println "INFERENCE DONE" - def matchResult = new File(testDir + 'similar.txt') + def matchResult = new File(testDir + 'similar.txt') matchResult.write('') - String allResultConfidence=""; - def resultConfidence = new File(testDir + 'similarwithConfidence.txt') + String allResultConfidence = ""; + def resultConfidence = new File(testDir + 'similarwithConfidence.txt') resultConfidence.write('') - DecimalFormat formatter = new DecimalFormat("#.##") + DecimalFormat formatter = new DecimalFormat("#.##") + // populates values with confidence required to check if not similar has more confidence for (GroundAtom atom : Queries.getAllAtoms(testDB, notSimilar)){ - String result = atom.toString().replaceAll("NOTSIMILAR","") - result = result.replaceAll("[()]","") - String[] text = result.split(",") - String result2 = text[0].trim() + "\t" + text[1].trim() + " " + atom.getValue() - def symResult2= text[1].trim() + "," + text[0].trim() + " " + atom.getValue() - if(formatter.format(atom.getValue())>"0.7"){ - - // println atom.getRegisteredGroundKernels(); - + String result = atom.toString().replaceAll("NOTSIMILAR","") + result = result.replaceAll("[()]","") + String[] text = result.split(",") + String result2 = text[0].trim() + "\t" + text[1].trim() + " " + atom.getValue() + def symResult2 = text[1].trim() + "," + text[0].trim() + " " + atom.getValue() + + if(formatter.format(atom.getValue()) > "0.7"){ if(text[0].toString().contains("aml1")){ - allResultConfidence+=result2 + '\n'; - } - else{ - allResultConfidence+=symResult2 + '\n'; - } + allResultConfidence += result2 + '\n'; } - + else{ + allResultConfidence += symResult2 + '\n'; + } + } } - - resultConfidence.append(allResultConfidence + '\n') - - String allResultsPositive=""; - String allResultsPositiveConf=""; + + resultConfidence.append(allResultConfidence + '\n') + + String allResultsPositive = ""; + String allResultsPositiveConf = ""; for (GroundAtom atom : Queries.getAllAtoms(testDB, similar)){ - //println atom.toString() + ": " + formatter.format(atom.getValue()) + //println atom.toString() + ": " + formatter.format(atom.getValue()) // only writes if its equal to 1 or u can set the threshold - if(formatter.format(atom.getValue())>"0.7"){ + if(formatter.format(atom.getValue()) > "0.7"){ // converting to format for evaluation String result = atom.toString().replaceAll("SIMILAR","") result = result.replaceAll("[()]","") @@ -829,8 +838,8 @@ public class DocumentAligment result = text[0].trim() + "," + text[1].trim() + "," + "truth:1" def symResult = text[1].trim() + "," + text[0].trim() + "," + "truth:1" def symResult2 = text[1].trim() + "\t" + text[0].trim() - String result2 = text[0].trim() + "\t" + text[1].trim() - + String result2 = text[0].trim() + "\t" + text[1].trim() + // adding elements with aml1: at start for correctness if(!removeSymetric(matchResult,symResult)&& !removeSymetric(matchResult,result)&& @@ -848,15 +857,15 @@ public class DocumentAligment } matchResult.append(allResultsPositive + '\n') resultConfidence.append(allResultsPositiveConf+ '\n') - + String allResultNegative=""; for (GroundAtom atom : Queries.getAllAtoms(testDB, notSimilar)){ - // println atom.toString() + ": " + formatter.format(atom.getValue()) + // println atom.toString() + ": " + formatter.format(atom.getValue()) // only writes if its equal to 1 or u can set the threshold - if(formatter.format(atom.getValue())>"0.7"){ - + if(formatter.format(atom.getValue()) > "0.7"){ + // converting to format for evaluation String result = atom.toString().replaceAll("NOTSIMILAR","") result = result.replaceAll("[()]","") @@ -865,7 +874,7 @@ public class DocumentAligment def symResult= text[1].trim() + "," + text[0].trim() + "," + "0" def trueResult= text[0].trim() + "," + text[1].trim() + "," + "truth:1" def trueSymResult= text[1].trim() + "," + text[0].trim() + "," + "truth:1" - + if(!removeSymetric(matchResult,symResult)&& !removeSymetric(matchResult,result) && !removeSymetric(matchResult,trueSymResult)&& @@ -880,46 +889,43 @@ public class DocumentAligment } } } - + matchResult.append(allResultNegative) - //ruleExplaination(notSimilar,"notSimilarRules.txt"); + //ruleExplaination(notSimilar,"notSimilarRules.txt"); //ruleExplaination(similar,"SimilarRules.txt"); - } - - /** * Evaluates the results of inference versus expected truth values */ public void evalResults() { - targetsPartition = new Partition(5) - truthPartition = new Partition(6) + targetsPartition = new Partition(5) + truthPartition = new Partition(6) def insert = data.getInserter(eval, targetsPartition) InserterUtils.loadDelimitedDataTruth(insert, testDir + "similar.txt") - // InserterUtils.loadDelimitedDataTruth(insert, testDir + "GoldStandard.txt") - + // InserterUtils.loadDelimitedDataTruth(insert, testDir + "GoldStandard.txt") + insert = data.getInserter(eval, truthPartition) - + //def goldStandardFile = new File(testDir + "GoldStandard.txt") //assert goldStandardFile.exists() : "file not found" - + //InserterUtils.loadDelimitedDataTruth(insert, testDir + "similar.txt") InserterUtils.loadDelimitedDataTruth(insert, testDir + "GoldStandard.txt") - + Database resultsDB = data.getDatabase(targetsPartition, [eval] as Set) Database truthDB = data.getDatabase(truthPartition, [eval] as Set) DiscretePredictionComparator dpc = new DiscretePredictionComparator(resultsDB) dpc.setBaseline(truthDB) DiscretePredictionStatistics stats = dpc.compare(eval) - + Double F1 = stats.getF1(DiscretePredictionStatistics.BinaryClass.POSITIVE) Double precision = stats.getPrecision(DiscretePredictionStatistics. - BinaryClass.POSITIVE) + BinaryClass.POSITIVE) Double recall = stats.getRecall(DiscretePredictionStatistics. - BinaryClass.POSITIVE) - + BinaryClass.POSITIVE) + System.out.println("Accuracy:" + stats.getAccuracy().round(2)) System.out.println("Error:" + stats.getError()) System.out.println("True Positive:" + stats.tp) @@ -932,15 +938,15 @@ public class DocumentAligment // Saving Precision and Recall results to file def resultsFile - + //Creating an unique name for the file def arrDir = testDir.split("/") def het = arrDir[4] def number = arrDir[5].split("-") - + if(util.ConfigManager.getExecutionMethod() == "true"){ resultsFile = new File(testDir + "Precision/" + arrDir[4] + "-" + - number[1] + "F1Training.txt") + number[1] + "F1Training.txt") } else{ resultsFile = new File(testDir + "Precision/" + "F1NoTraining.txt") @@ -962,15 +968,12 @@ public class DocumentAligment truthDB.close() } - + /** * Populates all the similar atoms between the concepts of two Documents using * the hasDocument predicate. - * - * @param db The database to populate. It should contain the hasDocument atoms + * @param db The database to populate. It should contain the hasDocument atoms */ - - void populateSimilar(Database db) { /* Collects the ontology concepts */ Set concepts = Queries.getAllAtoms(db, hasDocument) @@ -993,8 +996,6 @@ public class DocumentAligment } } - - } - + } \ No newline at end of file From f4f27642c81a0862ca1536a6bde57a0c83ec0030 Mon Sep 17 00:00:00 2001 From: igrangel Date: Thu, 31 Aug 2017 13:14:29 +0200 Subject: [PATCH 4/5] Adding the threshold as a parameter --- src/main/java/pslApproach/KGAlignment.groovy | 28 +++++++----- src/main/java/util/ConfigManager.java | 46 ++++++++++++-------- 2 files changed, 44 insertions(+), 30 deletions(-) diff --git a/src/main/java/pslApproach/KGAlignment.groovy b/src/main/java/pslApproach/KGAlignment.groovy index ba8197e..43e15d4 100644 --- a/src/main/java/pslApproach/KGAlignment.groovy +++ b/src/main/java/pslApproach/KGAlignment.groovy @@ -45,6 +45,7 @@ public class DocumentAligment private Partition testPredictions private Partition targetsPartition private Partition truthPartition + private String threshold def dir def testDir def trainDir @@ -55,6 +56,9 @@ public class DocumentAligment docAlign.execute() } + /** + * TODO to write comments + */ public void run() { config() @@ -68,6 +72,8 @@ public class DocumentAligment if (util.ConfigManager.getNegativeRules().equals("true")){ defineNotSimilarRules() } + + threshold = util.ConfigManager.getThreshold() setUpData() runInference() SemCPSMain main = new SemCPSMain(); @@ -812,7 +818,7 @@ public class DocumentAligment String result2 = text[0].trim() + "\t" + text[1].trim() + " " + atom.getValue() def symResult2 = text[1].trim() + "," + text[0].trim() + " " + atom.getValue() - if(formatter.format(atom.getValue()) > "0.7"){ + if(formatter.format(atom.getValue()) > threshold){ if(text[0].toString().contains("aml1")){ allResultConfidence += result2 + '\n'; } @@ -830,7 +836,7 @@ public class DocumentAligment //println atom.toString() + ": " + formatter.format(atom.getValue()) // only writes if its equal to 1 or u can set the threshold - if(formatter.format(atom.getValue()) > "0.7"){ + if(formatter.format(atom.getValue()) > threshold){ // converting to format for evaluation String result = atom.toString().replaceAll("SIMILAR","") result = result.replaceAll("[()]","") @@ -864,27 +870,27 @@ public class DocumentAligment // println atom.toString() + ": " + formatter.format(atom.getValue()) // only writes if its equal to 1 or u can set the threshold - if(formatter.format(atom.getValue()) > "0.7"){ + if(formatter.format(atom.getValue()) > threshold){ // converting to format for evaluation - String result = atom.toString().replaceAll("NOTSIMILAR","") - result = result.replaceAll("[()]","") + String result = atom.toString().replaceAll("NOTSIMILAR","") + result = result.replaceAll("[()]","") String[] text = result.split(",") - result = text[0].trim() + "," + text[1].trim() + "," + "0" - def symResult= text[1].trim() + "," + text[0].trim() + "," + "0" - def trueResult= text[0].trim() + "," + text[1].trim() + "," + "truth:1" - def trueSymResult= text[1].trim() + "," + text[0].trim() + "," + "truth:1" + result = text[0].trim() + "," + text[1].trim() + "," + "0" + def symResult = text[1].trim() + "," + text[0].trim() + "," + "0" + def trueResult = text[0].trim() + "," + text[1].trim() + "," + "truth:1" + def trueSymResult = text[1].trim() + "," + text[0].trim() + "," + "truth:1" if(!removeSymetric(matchResult,symResult)&& !removeSymetric(matchResult,result) && !removeSymetric(matchResult,trueSymResult)&& !removeSymetric(matchResult,trueResult)){ if(text[0].toString().contains("aml1")){ - allResultNegative+=result + '\n' + allResultNegative += result + '\n' } else{ - allResultNegative+=symResult + '\n' + allResultNegative += symResult + '\n' } } } diff --git a/src/main/java/util/ConfigManager.java b/src/main/java/util/ConfigManager.java index 50fc7f3..7627e73 100644 --- a/src/main/java/util/ConfigManager.java +++ b/src/main/java/util/ConfigManager.java @@ -37,10 +37,10 @@ public class ConfigManager { private static Model model; public static String filePath; - public final static String HET_NAMESPACE = "http://vocab.cs.uni-bonn.de/het#"; + public final static String SEMI_NAMESPACE = "https://w3id.org/i40/semi#"; public final static String URI_NAMESPACE = "http://uri4uri.net/vocab.html/#"; public final static String ONTO_NAMESPACE = "http://www.semanticweb.org/ontologies/2008/11/" - + "OntologySecurity.owl#"; + + "OntologySecurity.owl#"; public final static String STO_NAMESPACE = "https://w3id.org/i40/sto#"; /** @@ -57,7 +57,7 @@ public static ConfigManager getInstance() { } /** - * This method load the Configuration file parameters + * This method loads the Configuration file parameters */ public static Properties loadConfig() { prop = new Properties(); @@ -85,7 +85,6 @@ public static Properties loadConfig() { StmtIterator iterator = model.listStatements(); while (iterator.hasNext()) { - Statement stmt = iterator.nextStatement(); predicate = stmt.getPredicate(); @@ -93,7 +92,6 @@ public static Properties loadConfig() { literal = stmt.getLiteral(); literals.add(literal); - } for (int i = 0; i < predicates.size(); ++i) { @@ -108,12 +106,11 @@ public static Properties loadConfig() { } /** - * Get the general file path where all the files are located - * + * Gets the general file path where all the files are located * @return */ public static String getFilePath() { - if(filePath!=null){ + if(filePath != null){ return filePath; } String filePath = loadConfig().getProperty(URI_NAMESPACE + "path"); @@ -121,8 +118,7 @@ public static String getFilePath() { } /** - * Get the general file path where all the files are located - * + * Gets the general file path where all the files are located * @return */ public static String getOntoURIPath() { @@ -131,11 +127,9 @@ public static String getOntoURIPath() { } /** - * Get the general file path where all the test data files are located - * + * Gets the general file path where all the test data files are located * @return */ - public static boolean createDataPath() { String filePath = loadConfig().getProperty(URI_NAMESPACE + "path"); boolean dir = new File(filePath + "PSL/test/Precision").mkdirs(); @@ -143,6 +137,10 @@ public static boolean createDataPath() { return dir; } + /** + * Gets the path for Test Data + * @return + */ public static String getTestDataPath() { String filePath = loadConfig().getProperty(URI_NAMESPACE + "testDataPath"); return filePath; @@ -168,8 +166,7 @@ public static String getOntoPredicates() { } /** - * Get the general file path where all the test data files are located - * + * Gets the general file path where all the train data files are located * @return */ public static String getTrainDataPath() { @@ -177,6 +174,10 @@ public static String getTrainDataPath() { return filePath; } + /** + * Gets the Standard value, e.g., AML + * @return + */ public static String getStandard() { String standard = loadConfig().getProperty(STO_NAMESPACE + "Standard"); return standard; @@ -192,16 +193,23 @@ public static String getExperimentFolder() { } /** - * Reads the configuration of the experiment folder + * Reads whether negative rules will be used or not * @return true or false */ public static String getNegativeRules() { String filePath = loadConfig().getProperty(URI_NAMESPACE + "NegativeRules"); - if(filePath==null) - return "true"; + if(filePath == null) return "true"; return filePath; } - + /** + * Gets the threshold value configured to be used in the experiment. The default value is 0.5 + * @return 0.5 or given value + */ + public static String getThreshold() { + String threshold = loadConfig().getProperty(SEMI_NAMESPACE + "threshold"); + if(threshold == null) return "0.5"; //default + return threshold; + } } From 58b63b606b768a2ad6617ea1711430f5a99b9446 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 31 Aug 2017 14:26:30 +0300 Subject: [PATCH 5/5] removing duplicate code --- src/main/java/industryStandard/AML.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/industryStandard/AML.java b/src/main/java/industryStandard/AML.java index 6fbe920..00df8d1 100644 --- a/src/main/java/industryStandard/AML.java +++ b/src/main/java/industryStandard/AML.java @@ -69,8 +69,6 @@ public void addsDataforAML() throws FileNotFoundException { eClassCheck(); hasIdentifier(); } - - addGenericObject("hasRefSemantic", "hasCorrespondingAttributePath"); } /***