/** Demonstrates getIsas api function. */ protected void demo4() throws IOException, UnknownHostException, CycApiException { Log.current.println("Demonstrating getIsas api function.\n"); CycList isas = cycAccess.getIsas(cycAccess.getKnownConstantByName("BillClinton")); Log.current.println("\nThe obtained isas are:\n" + isas.cyclify()); }
// Opencyc // algrism***************************************************************************************************************************************************// private void sample() { // TODO Auto-generated method stub System.out.println("Starting Cyc NART examples."); try { access = new CycAccess(); // Log.current.println("Demonstrating getConstantGuid api function.\n"); // Guid a = access.getConstantGuid("apple"); CycConstant cycAdministrator = access.getKnownConstantByName("CycAdministrator"); System.out.println("Unique id ?" + cycAdministrator.guid); System.out.println("Unique id ?" + DefaultCycObject.toCompactExternalId("AppleInc")); CycList isas = access.getIsas(access.getKnownConstantByName("AppleInc")); Log.current.println("\nThe obtained isas are:\n" + isas.cyclify()); CycConstant generalCycKE = access.getKnownConstantByName("GeneralCycKE"); access.setCyclist(cycAdministrator); // needed to maintain // bookeeping information access.setKePurpose(generalCycKE); // needed to maintain bookeeping // information // find nart by external id (preferred lookup mechanism) CycNart apple = (CycNart) DefaultCycObject.fromCompactExternalId( "Mx8Ngh4rvVipdpwpEbGdrcN5Y29ycB4rvVjBnZwpEbGdrcN5Y29ycA", access); // access.getConstantId(""); // find nart by name (dispreferred because names in the KB can // change) CycNart apple2 = access.getCycNartFromCons( (CycList) CycLParserUtil.parseCycLDenotationalTerm("(FruitFn AppleTree)", true, access)); assert apple.equals(apple2) : "Lookup failed to produce equal results."; // getting the external id DefaultCycObject.tofor a NART String appleEID = DefaultCycObject.toCompactExternalId(apple, access); // creating a nart // There is no direct way of creating NARTs, they are an // implementation detail // of the inference engine. However, if you make an assertion using // arguments // to a reifiable function that the inference engine hasn't seen // before, then it will be create // automatically. CycNart elmFruit = new CycNart( access.getKnownConstantByName("FruitFn"), access.getKnownConstantByName("ElmTree")); // NOTE: the previous call only makes the NART locally and not in // the KB // Asserting the isa and genls relations // every new term should have at least 1 isa assertion made on it access.assertIsa(elmFruit, CycAccess.collection, CycAccess.baseKB); // Note: the previous line causes the new NART to be created in the // KB! // Every new collection should have at least 1 genls assertion made // on it, // however, in this case, the inference engine has made it for you // since // any new terms involving FruitFn's must be types of fruits. // access.assertGenls(elmFruit, // access.getKnownConstantByName("Fruit"), CycAccess.baseKB); // verify genls relation assert access.isSpecOf(elmFruit, access.getKnownConstantByName("Fruit"), CycAccess.baseKB) : "Good grief! Elm fruit isn't known to be a type of fruit."; // find everything that is an apple System.out.println("Got instances of Apple: " + access.getInstances(apple)); System.out.println( "Got instances of Apple: " + access.getAllInstances(apple, CycAccess.baseKB)); // find everything that a apple is a type of System.out.println( "Got generalizations of Apple: " + access.getAllGenls(apple, CycAccess.baseKB)); // find everything that is a type of apple System.out.println( "Got specializations of Apple: " + access.getAllSpecs(apple, CycAccess.baseKB)); // generating NL // System.out.println("The concept " + apple.cyclify() // + " can be referred to in English as '" + // access.getGeneratedPhrase(apple) + "'."); // Killing a NART -- removing a NART and all assertions involving // that NART from the KB // Warning: you can potentially do serious harm to the KB if you // remove critical information access.kill(elmFruit); // CycConstant dog2 = access.getKnownConstantByName("Dog"); // CycFort snowSkiing = access.getKnownConstantByName("SnowSkiing"); } catch (UnknownHostException nohost) { nohost.printStackTrace(); } catch (IOException io) { io.printStackTrace(); } catch (CycApiException cyc_e) { cyc_e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } System.out.println("Finished."); }