protected void importDataProperty(OWLOntology o, OWLDataProperty dataTypeProperty) { String propertyIRI = dataTypeProperty.getIRI().toString(); String propertyDisplayName = getLabel(o, dataTypeProperty); PropertyType propertyType = getPropertyType(o, dataTypeProperty); boolean userVisible = getUserVisible(o, dataTypeProperty); boolean searchable = getSearchable(o, dataTypeProperty); Boolean displayTime = getDisplayTime(o, dataTypeProperty); Double boost = getBoost(o, dataTypeProperty); if (propertyType == null) { throw new LumifyException("Could not get property type on data property " + propertyIRI); } for (OWLClassExpression domainClassExpr : dataTypeProperty.getDomains(o)) { OWLClass domainClass = domainClassExpr.asOWLClass(); String domainClassUri = domainClass.getIRI().toString(); Concept domainConcept = getConceptByIRI(domainClassUri); checkNotNull(domainConcept, "Could not find class with uri: " + domainClassUri); LOGGER.info("Adding data property " + propertyIRI + " to class " + domainConcept.getTitle()); ArrayList<PossibleValueType> possibleValues = getPossibleValues(o, dataTypeProperty); Collection<TextIndexHint> textIndexHints = getTextIndexHints(o, dataTypeProperty); addPropertyTo( domainConcept, propertyIRI, propertyDisplayName, propertyType, possibleValues, textIndexHints, userVisible, searchable, displayTime, boost); } }
/** * Highlight concepts that have already been resolved, but do not run solver. Otherwise, do * nothing. * * @param objects The set of objects to highlight. * @exception IllegalActionException Thrown if there is an error getting the colors for the * resolved concept values. */ public void highlightConcepts(Set<Object> objects) throws IllegalActionException { if (objects != null) { // Get the PropertySolver. OntologySolver solver = (OntologySolver) getContainer(); for (Object object : objects) { if (object instanceof NamedObj) { Concept concept = solver.getConcept(object); if (concept != null) { ColorAttribute conceptColor = concept.getColor(); if (conceptColor != null) { String request = "<property name=\"_highlightColor\" " + "class=\"ptolemy.actor.gui.ColorAttribute\" value=\"" + conceptColor.getExpression() + "\"/>"; MoMLChangeRequest change = new MoMLChangeRequest(this, (NamedObj) object, request, false); ((NamedObj) object).requestChange(change); } } } } // Force a single repaint after all the above requests have been processed. solver.requestChange(new MoMLChangeRequest(this, solver, "<group/>")); } }
private Concept createConceptWithName(String name) { Concept concept = new Concept(new Random().nextInt()); ConceptName conceptName = new ConceptName(); conceptName.setName(name); conceptName.setLocale(Context.getLocale()); conceptName.setLocalePreferred(true); concept.addName(conceptName); return concept; }
private boolean matchesConcept(Concept concept, String text, boolean isRegex) { for (String name : concept.getNames()) { if (matches(name, text, isRegex)) return true; } if (matches(concept.getCode(), text, isRegex)) return true; if (matches(concept.getCodeUC(), text, isRegex)) return true; if (matches(concept.getPrintSymbol(), text, isRegex)) return true; return false; }
public CodeableConceptDt getTRValueSetCodeableConcept( Concept concept, String valueSetURL, CodeableConceptDt codeableConcept) { CodingDt coding = codeableConcept.addCoding(); if (null != idMappingsRepository.findByInternalId(concept.getUuid())) { coding.setCode(getTRValueSetCode(concept)); coding.setSystem(valueSetURL); } coding.setDisplay(concept.getName().getName()); return codeableConcept; }
public static Map<EdamUri, Concept> load(String edamPath) throws OWLOntologyCreationException { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLOntology ontology = manager.loadOntologyFromOntologyDocument(new File(edamPath)); String prefix = ontology.getOntologyID().getOntologyIRI().get().toString(); return ontology .classesInSignature() .filter(c -> EdamUri.isEdamUri(c.getIRI().toString(), prefix)) .collect( Collectors.toMap( c -> new EdamUri(c.getIRI().toString(), prefix), c -> { Concept concept = new Concept(); EntitySearcher.getAnnotations(c, ontology) .forEachOrdered( a -> { if (a.getProperty().isLabel()) concept.setLabel(a.getValue().asLiteral().get().getLiteral()); else if (a.getProperty().isDeprecated()) concept.setObsolete(true); else if (a.getProperty() .toStringID() .equals( "http://www.geneontology.org/formats/oboInOwl#hasExactSynonym") && a.getValue().asLiteral().isPresent()) concept.addExactSynonym(a.getValue().asLiteral().get().getLiteral()); else if (a.getProperty() .toStringID() .equals( "http://www.geneontology.org/formats/oboInOwl#hasNarrowSynonym") && a.getValue().asLiteral().isPresent()) concept.addNarrowSynonym(a.getValue().asLiteral().get().getLiteral()); else if (a.getProperty() .toStringID() .equals( "http://www.geneontology.org/formats/oboInOwl#hasBroadSynonym") && a.getValue().asLiteral().isPresent()) concept.addBroadSynonym(a.getValue().asLiteral().get().getLiteral()); else if (a.getProperty() .toStringID() .equals( "http://www.geneontology.org/formats/oboInOwl#hasDefinition") && a.getValue().asLiteral().isPresent()) concept.setDefinition(a.getValue().asLiteral().get().getLiteral()); else if (a.getProperty().isComment() && a.getValue().asLiteral().isPresent()) concept.setComment(a.getValue().asLiteral().get().getLiteral()); }); if (concept.getLabel().isEmpty()) throw new IllegalStateException( String.format("Label of concept %s is empty", c.getIRI())); return concept; }, (u, v) -> { throw new IllegalStateException(String.format("Duplicate key %s", u)); }, LinkedHashMap::new)); }
public String getTRValueSetCode(Concept concept) { for (ConceptMap mapping : concept.getConceptMappings()) { if (mapping.getConceptMapType().getUuid().equals(ConceptMapType.SAME_AS_MAP_TYPE_UUID)) { return mapping.getConceptReferenceTerm().getCode(); } } for (ConceptName conceptName : concept.getShortNames()) { return conceptName.getName(); } return concept.getName().getName(); }
private Concept mockConcept() { QNameUtil qnames = QNameUtil.instance(); Concept mocked = mock(Concept.class); try { when(mocked.getName()) .thenReturn(qnames.createQNameInPreconstructedNamespace(CONCEPT_LOCALNAME)); } catch (Exception ex) { throw new Error(ex); } return mocked; }
private void addTRCodingForConcept( Concept concept, IdMappingsRepository idMappingsRepository, CodeableConceptDt codeableConcept) { IdMapping idMapping = idMappingsRepository.findByInternalId(concept.getUuid()); if (idMapping != null) { addFHIRCoding( codeableConcept, idMapping.getExternalId(), idMapping.getUri(), concept.getName().getName()); } }
/** Gets or creates a Concept with a given UUID and name. */ public static Concept getConcept(String name, String uuid, String typeUuid) { ConceptService conceptService = Context.getConceptService(); Concept concept = conceptService.getConceptByUuid(uuid); if (concept == null) { concept = new Concept(); concept.setUuid(uuid); concept.setShortName(new ConceptName(name, new Locale("en"))); concept.setDatatype(conceptService.getConceptDatatypeByUuid(typeUuid)); concept.setConceptClass(conceptService.getConceptClassByUuid(ConceptClass.MISC_UUID)); conceptService.saveConcept(concept); } return concept; }
/* * Loads a concept group from XML element */ private Group loadGroup(Element element) { Group group = new Group(); group.name = element.getAttributeValue("name"); List children = element.getChildren("concept"); for (Iterator it = children.iterator(); it.hasNext(); ) { Concept concept = new Concept(); Element e = (Element) it.next(); concept.id = (e.getAttributeValue("id")); concept.rubric = (e.getAttributeValue("rubric")); group.addConcept(concept); } return group; }
public CodeableConceptDt addTRCodingOrDisplay(Concept concept) { CodeableConceptDt codeableConceptDt = addTRCoding(concept); if (CollectionUtils.isEmpty(codeableConceptDt.getCoding())) { CodingDt coding = codeableConceptDt.addCoding(); coding.setDisplay(concept.getName().getName()); } return codeableConceptDt; }
/** * Get the concept description that is tied to the concept name that was used when making this * observation * * @return ConceptDescription the description used */ public ConceptDescription getConceptDescription() { // if we don't have a question for this concept, // then don't bother looking for a description if (getConcept() == null) return null; // ABKTOD: description in which locale? return concept.getDescription(); }
/** * @deprecated Use {@link Concept#getShortestName(Locale, Boolean)} instead. * @return Returns the appropriate short name */ @Deprecated public String getShortestName() { if (concept != null) { ConceptName bestShortName = concept.getShortestName(this.locale, false); if (bestShortName != null) return bestShortName.getName(); } return getName(); }
/** * @deprecated * @return Returns the shortName. */ @Deprecated public String getShortName() { if (concept != null) { ConceptName bestShortName = concept.getShortNameInLocale(Context.getLocale()); if (bestShortName != null) return bestShortName.getName(); } return null; }
/** * @deprecated * @return Returns the description. */ @Deprecated public String getDescription() { if (concept != null) { ConceptDescription description = concept.getDescription(); if (description != null) return description.getDescription(); } return null; }
public List<TemplateRule> getTemplateRules() { templateRules = new ArrayList<TemplateRule>(); Rules rules = concept.getRules(); List<JAXBElement<? extends AbstractRule>> abstractRules = rules.getAbstractRule(); for (JAXBElement<? extends AbstractRule> jAXBElementRule : abstractRules) { TemplateRule templateRule = (TemplateRule) jAXBElementRule.getValue(); templateRules.add(templateRule); } return templateRules; }
public CodeableConceptDt addTRCoding(Concept concept) { CodeableConceptDt codeableConcept = new CodeableConceptDt(); Collection<ConceptMap> conceptMappings = concept.getConceptMappings(); for (ConceptMap mapping : conceptMappings) { if (mapping.getConceptMapType().getUuid().equals(ConceptMapType.SAME_AS_MAP_TYPE_UUID)) { addTRCodingsForReferenceTerms(concept, idMappingsRepository, codeableConcept, mapping); } } addTRCodingForConcept(concept, idMappingsRepository, codeableConcept); return codeableConcept; }
/** * Show all concept values as text annotations on each model element. * * @exception IllegalActionException If getting the resolved concept fails. */ public void showConceptAnnotations() throws IllegalActionException { // Get the PropertySolver. OntologySolver solver = (OntologySolver) getContainer(); for (Object propertyable : solver.getAllPropertyables()) { if (propertyable instanceof NamedObj) { Concept concept = solver.getConcept(propertyable); if (concept != null) { String request = "<property name=\"_showInfo\" class=\"ptolemy.data.expr.StringParameter\" value=\"" + concept.toString() + "\"/>"; MoMLChangeRequest change = new MoMLChangeRequest(this, (NamedObj) propertyable, request, false); ((NamedObj) propertyable).requestChange(change); } } } // Force a single repaint after all the above requests have been processed. solver.requestChange(new MoMLChangeRequest(this, solver, "<group/>")); }
public static Map<Concept, TreeSet<SNP>> run( Map<Concept, LinkedList<Gene>> conceptToGenes, Map<Gene, LinkedList<SNP>> geneToSNPs) { Map<Concept, TreeSet<SNP>> map = new HashMap<Concept, TreeSet<SNP>>(); for (Concept concept : conceptToGenes.keySet()) { TreeSet<SNP> snpSet = new TreeSet<SNP>(); for (Gene gene : conceptToGenes.get(concept)) { if (geneToSNPs.containsKey(gene)) { concept.addGene(gene); for (SNP snp : geneToSNPs.get(gene)) { snpSet.add(snp); concept.addSNP(snp); } } } map.put(concept, snpSet); } return map; }
/** * 获取概念的所有义原 * * @param concept * @param includeMainSememe 是否包含主义原 * @return */ private List<String> getAllSememes(Concept concept, boolean includeMainSememe) { List<String> results = new ArrayList<String>(); if (concept != null) { if (includeMainSememe) { results.add(concept.getMainSememe()); } for (String sememe : concept.getSecondSememes()) { results.add(sememe); } for (String sememe : concept.getSymbolSememes()) { results.add(sememe); } for (String sememe : concept.getRelationSememes()) { results.add(sememe); } } return results; }
/** * This is a legacy test for the older vocabularyServiceResponse.xml * * <p>It tests our concepts still return EVEN if we don't define top level concepts */ @Test public void testGetConcepts() throws Exception { String responseXml = ResourceUtil.loadResourceAsString( "org/auscope/portal/core/test/responses/sissvoc/vocabularyServiceResponse.xml"); Document responseDoc = DOMUtil.buildDomFromString(responseXml); Node rdfNode = (Node) DOMUtil.compileXPathExpr("rdf:RDF", new VocabNamespaceContext()) .evaluate(responseDoc, XPathConstants.NODE); ConceptFactory cf = new ConceptFactory(); Concept[] actualConcepts = cf.parseFromRDF(rdfNode); Assert.assertEquals("There are 27 concepts", 27, actualConcepts.length); // Must contain: Siltstone - concrete aggregate boolean found = false; for (Concept concept : actualConcepts) { if (concept.getPreferredLabel().equals("Siltstone - concrete aggregate")) { found = true; break; } } Assert.assertTrue("Must contain: Siltstone - concrete aggregate", found); // Must contain: Gneiss - crusher dust found = false; for (Concept concept : actualConcepts) { if (concept.getPreferredLabel().equals("Gneiss - crusher dust")) { found = true; break; } } Assert.assertTrue("Must contain: Gneiss - crusher dust", found); }
private void addTRCodingsForReferenceTerms( Concept concept, IdMappingsRepository idMappingsRepository, CodeableConceptDt codeableConcept, ConceptMap mapping) { ConceptReferenceTerm conceptReferenceTerm = mapping.getConceptReferenceTerm(); IdMapping idMapping = idMappingsRepository.findByInternalId(conceptReferenceTerm.getUuid()); if (idMapping != null) { addFHIRCoding( codeableConcept, conceptReferenceTerm.getCode(), idMapping.getUri(), concept.getName().getName()); } }
private void processMatchedConcepts( List<Concept> matchedConcepts, String matchedText, int tokenPosn, Map<Concept, Score> tokTable, PrintWriter pw) { // Increment match score of the matched concept and record information // about where in the article it was found for (Concept c : matchedConcepts) { Score cnt = tokTable.get(c); if (cnt == null) { tokTable.put(c, new Score(tokenPosn)); } else { cnt.addMatch(tokenPosn); } // Output the concept to the token file for debugging purposes if (pw != null) { pw.println(c.getName() + "<" + c.getKey() + ">:" + tokenPosn + ":TEXT=" + matchedText); } System.out.println( c.getName() + "<" + c.getKey() + ">:" + tokenPosn + ":TEXT=" + matchedText); } }
public static void MDVgenerate(String modelPath) throws ParserConfigurationException, SAXException, IOException, TException, UnknownWordException { com.medallia.word2vec.Word2VecModel model = Word2Vec_Medallia.loadModel(modelPath); LandxmlLexicon lexicon = readLandXML(); HashMap<Integer, LandxmlNode> landXMLEnt = lexicon.getMap(); try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { while (true) { System.out.print("Enter word or term (press ENTER to break): "); String phrase = br.readLine().trim(); if (phrase.equals("")) { System.out.println("Programe is shut off."); break; } // interpreting input string List<Concept> cons = Concept.getConcepts(phrase); TreeMap<String, Double> matchEntries = new TreeMap<String, Double>(); for (Concept con : cons) { matchEntries.putAll(lexicon.searchAlgorithm2(model, con, 30, 10, 0.3)); } // print the results System.out.println("********Mapping result**********************************"); System.out.println("--------Required data---------------------LandXML entity"); matchEntries = (TreeMap<String, Double>) shortTreeMap.sortByValues(matchEntries); int i = 0; for (Entry e : matchEntries.entrySet()) { i++; if (i > 5) break; String sourceEnt = e.getKey() + ":" + e.getValue(); System.out.println(sourceEnt); } System.out.println("********************************************************"); } } }
private void setIconProperty( Concept concept, File inDir, String glyphIconFileName, String propertyKey, Authorizations authorizations) throws IOException { if (glyphIconFileName != null) { File iconFile = new File(inDir, glyphIconFileName); if (!iconFile.exists()) { throw new RuntimeException("Could not find icon file: " + iconFile.toString()); } InputStream iconFileIn = new FileInputStream(iconFile); try { StreamingPropertyValue value = new StreamingPropertyValue(iconFileIn, byte[].class); value.searchIndex(false); value.store(true); concept.setProperty( propertyKey, value, OntologyRepository.VISIBILITY.getVisibility(), authorizations); } finally { iconFileIn.close(); } } }
public DisplayableConcept find(Concept key) { return (DisplayableConcept) (conceptUniqueIdentifierToConceptEntries.get(key.getConceptUniqueIdentifier())); }
/** * Entry point of the inference engine * * @param tLink The selected TaskLink, which will provide a task * @param bLink The selected TermLink, which may provide a belief * @param memory Reference to the memory */ public static void reason(TaskLink tLink, TermLink bLink, Memory memory) { Task task = memory.currentTask; Sentence taskSentence = task.getSentence(); Term taskTerm = (Term) taskSentence.getContent().clone(); // cloning for substitution Term beliefTerm = (Term) bLink.getTarget().clone(); // cloning for substitution Concept beliefConcept = memory.termToConcept(beliefTerm); Sentence belief = null; if (beliefConcept != null) { belief = beliefConcept.getBelief(task); } memory.currentBelief = belief; // may be null if (belief != null) { LocalRules.match(task, belief, memory); } if (!memory.noResult()) { return; } short tIndex = tLink.getIndex(0); short bIndex = bLink.getIndex(0); switch (tLink.getType()) { // dispatch first by TaskLink type case TermLink.SELF: switch (bLink.getType()) { case TermLink.COMPONENT: compoundAndSelf((CompoundTerm) taskTerm, beliefTerm, true, memory); break; case TermLink.COMPOUND: compoundAndSelf((CompoundTerm) beliefTerm, taskTerm, false, memory); break; case TermLink.COMPONENT_STATEMENT: if (belief != null) { SyllogisticRules.detachment(task.getSentence(), belief, bIndex, memory); } break; case TermLink.COMPOUND_STATEMENT: if (belief != null) { SyllogisticRules.detachment(belief, task.getSentence(), bIndex, memory); } break; case TermLink.COMPONENT_CONDITION: if (belief != null) { bIndex = bLink.getIndex(1); SyllogisticRules.conditionalDedInd( (Implication) taskTerm, bIndex, beliefTerm, tIndex, memory); } break; case TermLink.COMPOUND_CONDITION: if (belief != null) { bIndex = bLink.getIndex(1); SyllogisticRules.conditionalDedInd( (Implication) beliefTerm, bIndex, taskTerm, tIndex, memory); } break; } break; case TermLink.COMPOUND: switch (bLink.getType()) { case TermLink.COMPOUND: compoundAndCompound((CompoundTerm) taskTerm, (CompoundTerm) beliefTerm, memory); break; case TermLink.COMPOUND_STATEMENT: compoundAndStatement( (CompoundTerm) taskTerm, tIndex, (Statement) beliefTerm, bIndex, beliefTerm, memory); break; case TermLink.COMPOUND_CONDITION: if (belief != null) { if (beliefTerm instanceof Implication) { SyllogisticRules.conditionalDedInd( (Implication) beliefTerm, bIndex, taskTerm, -1, memory); } else if (beliefTerm instanceof Equivalence) { SyllogisticRules.conditionalAna( (Equivalence) beliefTerm, bIndex, taskTerm, -1, memory); } } break; } break; case TermLink.COMPOUND_STATEMENT: switch (bLink.getType()) { case TermLink.COMPONENT: componentAndStatement( (CompoundTerm) memory.currentTerm, bIndex, (Statement) taskTerm, tIndex, memory); break; case TermLink.COMPOUND: compoundAndStatement( (CompoundTerm) beliefTerm, bIndex, (Statement) taskTerm, tIndex, beliefTerm, memory); break; case TermLink.COMPOUND_STATEMENT: if (belief != null) { // bIndex = bLink.getIndex(1); syllogisms(tLink, bLink, taskTerm, beliefTerm, memory); } break; case TermLink.COMPOUND_CONDITION: if (belief != null) { bIndex = bLink.getIndex(1); if (beliefTerm instanceof Implication) { conditionalDedIndWithVar( (Implication) beliefTerm, bIndex, (Statement) taskTerm, tIndex, memory); } } break; } break; case TermLink.COMPOUND_CONDITION: switch (bLink.getType()) { case TermLink.COMPOUND_STATEMENT: if (belief != null) { // if (beliefTerm instanceof Implication) // TODO adding instanceof test changes results of Example-NAL6-in.txt // TODO maybe put instanceof test within conditionalDedIndWithVar() conditionalDedIndWithVar( (Implication) taskTerm, tIndex, (Statement) beliefTerm, bIndex, memory); } break; } break; } }
/** Use example for Context and ConceptLattice classes * */ public static void ExampleContext(String name) { try { // load an IS from the "ISrules.txt" file String nameContext = name + ".txt"; Context base = new Context(inputDir + nameContext); // create the directory to save files File f = new File(outputDir + name); f.mkdir(); // create the Readme file name = name + File.separator + name; BufferedWriter file = new BufferedWriter(new FileWriter(outputDir + name + "Readme.txt")); String log = "EXAMPLE FOR CONTEXT AND CONCEPTLATTICE CLASSES\n"; log += "-----------------------------------------\n"; log += "-> Initial context:\n " + base + "\n"; System.out.println(log); file.write(log); // compute the immediate successors of a concept from the context using Limited Object Access // algorihtm TreeSet<Comparable> setA = new TreeSet(); setA.add(base.getAttributes().first()); setA.addAll(base.closure(setA)); TreeSet<Comparable> setB = new TreeSet(); setB.addAll(base.getExtent(base.closure(setA))); Concept concept = new Concept(setA, setB); log = "Chosen concept " + concept.toString(); System.out.println(log); file.write(log); ArrayList<TreeSet<Comparable>> immsucc = concept.immediateSuccessorsLOA(base); log = "First immediate successor concept " + new Concept(immsucc.get(0), base.getExtent(immsucc.get(0))) + "\n"; System.out.println(log); file.write(log); // computes the precedence graph of the context DGraph prec = base.precedenceGraph(); String namePrecGraph = name + "PrecedenceGraph.dot"; prec.save(outputDir + namePrecGraph); log = "Precedence graph of Context saved in " + namePrecGraph + "\n"; System.out.println(log + prec.toString()); file.write(log); // computes and prints the concept lattice of the context with NextClosure ConceptLattice CLNC = base.closedSetLattice(false); String nameCLNC = name + "ClosedSetLatticeNextClosure.dot"; CLNC.save(outputDir + nameCLNC); log = "-> Closed set lattice of Context (generated by Next Closure algorithm) saved in " + nameCLNC + "\n"; System.out.println(log + CLNC.toString()); file.write(log); // computes and prints the closed set lattice of the context with Bordat ConceptLattice CLBordat = base.closedSetLattice(true); String nameCLBordat = name + "ClosedSetLatticeBordat.dot"; CLBordat.save(outputDir + nameCLBordat); log = "-> Closed set lattice of Context (generated by Bordat's algorithm) saved in " + nameCLBordat + "\n"; System.out.println(log + CLBordat.toString()); file.write(log); // computes and prints the concept lattice of the context with Bordat ConceptLattice CBordat = base.conceptLattice(true); String nameCBordat = name + "ConceptLatticeBordat.dot"; CBordat.save(outputDir + nameCBordat); log = "-> Concept lattice of Context (generated by Bordat's algorithm) saved in " + nameCBordat + "\n"; System.out.println(log + CBordat.toString()); file.write(log); // computes dependance graph, minimal generators and canonical direct basis log = "-> Components generated while Bordat's algorithm computes the lattice:\n"; DGraph ODG = CLBordat.getDependencyGraph(); String nameODG = name + "DependanceGraphOfClosedSetLattice.dot"; ODG.save(outputDir + nameODG); log += "Dependance graph of closed set lattice saved in " + nameODG + "\n"; System.out.println(log + ODG.toString()); file.write(log); TreeSet MinGen = CLBordat.getMinimalGenerators(); log = "Minimal generators of closed set lattice : " + MinGen + "\n"; ImplicationalSystem BCD = CLBordat.getCanonicalDirectBasis(); String nameBCD = name + "CanonicalDirectBasisOfClosedSetLattice.txt"; BCD.save(outputDir + nameBCD); log += "Canonical direct basis of closed set lattice saved in " + nameBCD + ": \n" + BCD.toString(); System.out.println(log); file.write(log); // computes the reduction and the closed set lattice of the context Context reduit = new Context(base); reduit.reduction(); String nameReduit = name + "Reduction.txt"; base.save(outputDir + nameReduit); log = "Reduced context saved in " + nameReduit + ": \n" + reduit; ConceptLattice CLReduit = base.closedSetLattice(true); String nameCLReduit = name + "ClosedSetLatticeOfReducedContext.dot"; CLReduit.save(outputDir + nameCLReduit); log += "Closed set lattice of the reduced context saved in " + nameCLReduit + "\n"; System.out.println(log + CLReduit.toString()); file.write(log); // BIJECTION log = "--- BIJECTION --- \n"; log += "Concept lattice of initial context (" + nameCLBordat + ") isomorphic to\n"; log += "Concept lattice of the reduced context (" + nameCLReduit + ")\n"; log += "-----------------\n"; // computes the table of the concept lattice od the context Context table = CBordat.getTable(); String nameTable = name + "TableOfConceptLattice.txt"; base.save(outputDir + nameTable); log = "-> Table of the concept lattice saved in " + nameTable + ": \n" + table; System.out.println(log); file.write(log); // BIJECTION log = "--- BIJECTION --- \n"; log += "Reduction of the initial context " + reduit + ") isomorphic to\n"; log += "Table of the its concept lattice (" + nameTable + ")\n"; log += "-----------------\n"; // computes the closed set lattice of the CDB ConceptLattice CLBCD = BCD.closedSetLattice(true); String nameCLBCD = name + "ConceptLatticeOfBCD.dot"; CLBCD.save(outputDir + nameCLBCD); log = "Concept lattice of the CDB saved in " + nameCLBCD + "\n"; System.out.println(log + CLBCD.toString()); file.write(log); // BIJECTION log = "--- BIJECTION --- \n"; log += "Concept lattice of the initial context (" + nameCLBordat + ") is isomorphic to \n"; log += "is isomorphic to concept lattice of its canonical directe basis (" + nameCLBCD + ")\n"; log += "-----------------\n"; System.out.println(log); file.write(log); file.close(); } catch (Exception e) { } }
/** * 计算两个概念的组合概念, 计算过程中根据参照概念修正组合结果, 实际应用中的两个概念 应具有一定的先后关系(体现汉语“重心后移”特点), 如对于娱乐场,first="娱乐" * second="场", 另外, 还需要修正第一个概念中的符号义原对于第二个概念主义原的实际关系,当参照概念起作用时, * 即大于指定的阈值,则需要判断是否把当前义原并入组合概念中,对于第一个概念,还需要同时修正符号关系, 符合关系与参照概念保持一致. * * @param head 第一个概念 * @param tail 第二个概念 * @param ref 参照概念 * @return */ public Concept autoCombineConcept(Concept head, Concept tail, Concept ref) { // 一个为null,一个非null,直接返回非null的克隆新概念 if (tail == null && head != null) { return new Concept(head.getWord(), head.getPos(), head.getDefine()); } else if (head == null && tail != null) { return new Concept(tail.getWord(), tail.getPos(), tail.getDefine()); } // 第二个概念不是实词,直接返回第一个概念 if (!tail.isSubstantive()) { return new Concept(head.getWord() + tail.getWord(), head.getPos(), head.getDefine()); } // 如果没有参照概念、或者参照概念为虚词,则直接相加,即参照概念不再起作用 if (ref == null || !ref.isSubstantive()) { String define = tail.getDefine(); // define存放新的定义结果 // 把第一个概念的定义合并到第二个上 List<String> sememeList = getAllSememes(head, true); for (String sememe : sememeList) { if (!define.contains(sememe)) { define = define + "," + sememe; } } return new Concept(head.getWord() + tail.getWord(), tail.getPos(), define); } // 正常处理:参照概念非空,并且是实词概念 String define = tail.getMainSememe(); // define存放新的定义结果 List<String> refSememes = getAllSememes(ref, false); List<String> headSememes = getAllSememes(head, true); List<String> tailSememes = getAllSememes(tail, false); // 如果参照概念与第二个概念的主义原的义原相似度大于阈值THETA, // 则限制组合概念定义中与第二个概念相关的义原部分为: 第二个概念的义原集合与参照概念义原集合的模糊交集 double main_similarity = sememeParser.getSimilarity(tail.getMainSememe(), ref.getMainSememe()); if (main_similarity >= PARAM_THETA) { // 求交集 for (String tail_sememe : tailSememes) { double max_similarity = 0.0; String max_ref_sememe = null; for (String ref_sememe : refSememes) { double value = sememeParser.getSimilarity(tail_sememe, ref_sememe); if (value > max_similarity) { max_similarity = value; max_ref_sememe = ref_sememe; } } // 如果tail_sememe与参照概念中的相似度最大的义原经theta约束后超过阈值XI,则加入生成的组合概念定义中 if (max_similarity * main_similarity >= PARAM_XI) { define = define + "," + tail_sememe; refSememes.remove(max_ref_sememe); } } // end for } else { define = tail.getDefine(); } // end if // 合并第一个概念的义原到组合概念定义中 for (String head_sememe : headSememes) { double max_similarity = 0.0; String max_ref_sememe = ""; for (String ref_sememe : refSememes) { double value = sememeParser.getSimilarity(getPureSememe(head_sememe), getPureSememe(ref_sememe)); if (value > max_similarity) { max_similarity = value; max_ref_sememe = ref_sememe; } } if (main_similarity * max_similarity >= PARAM_OMEGA) { // 调整符号关系, 用参照概念的符号关系替换原符号关系, 通过把参照概念的非符号部分替换成前面义原的非符号内容即可 String sememe = max_ref_sememe.replace(getPureSememe(max_ref_sememe), getPureSememe(head_sememe)); if (!define.contains(sememe)) { define = define + "," + sememe; } } else if (!define.contains(head_sememe)) { define = define + "," + head_sememe; } } // end for return new Concept(head.getWord() + tail.getWord(), tail.getPos(), define); }