Exemplo n.º 1
0
 /** Demonstrates usage of CycNart and getInstanceSiblings api function. */
 protected void demo12() throws IOException, UnknownHostException, CycApiException {
   Log.current.println("Demonstrating CycNart and getInstanceSiblings api function.\n");
   CycNart usGovernment =
       new CycNart(
           cycAccess.getKnownConstantByName("GovernmentFn"),
           cycAccess.getKnownConstantByName("UnitedStatesOfAmerica"));
   CycList siblings = cycAccess.getInstanceSiblings(usGovernment);
   Log.current.println(
       "\nThe obtained instance sibling terms of "
           + usGovernment
           + "\nare:\n"
           + siblings.cyclify());
 }
Exemplo n.º 2
0
 /** Demonstrates usage of the generateDisambiguationPhraseAndTypes api function. */
 protected void demo17() throws IOException, UnknownHostException, CycApiException {
   if (cycAccess.isOpenCyc()) {
     Log.current.println("\nThis demo is not available in OpenCyc");
   } else {
     Log.current.println(
         "Demonstrating usage of the generateDisambiguationPhraseAndTypes api function.\n");
     CycFort mt = cycAccess.getKnownConstantByName("PeopleDataMt");
     CycList objects = cycAccess.makeCycList("(#$Penguin #$PittsburghPenguins)");
     CycList disambiguationExpression = cycAccess.generateDisambiguationPhraseAndTypes(objects);
     Log.current.println(
         "the result of disambiguating the objects \""
             + objects.cyclify()
             + "\" is\n"
             + disambiguationExpression);
   }
 }
  /**
   * Provides the main method for an EELD DAML export.
   *
   * @parameter args the optional command line arguments
   */
  public static void main(String[] args) {
    try {
      cycAccess =
          new CycAccess(
              CycConnection.DEFAULT_HOSTNAME,
              CycConnection.DEFAULT_BASE_PORT,
              CycConnection.DEFAULT_COMMUNICATION_MODE,
              CycAccess.DEFAULT_CONNECTION);
      /*
          new CycAccess(CycConnection.DEFAULT_HOSTNAME,
                        3620,
                        CycConnection.DEFAULT_COMMUNICATION_MODE,
                        CycAccess.DEFAULT_CONNECTION);
      */
      ExportDaml exportDaml = new ExportDaml(cycAccess);
      exportDaml.verbosity = ExportDaml.DEFAULT_VERBOSITY;
      // exportDaml.verbosity = 9;

      String choice = "eeld-core";
      if (args.length > 0) choice = args[0];

      Log.current.println("Choosing KB selection: " + choice);
      // These require the Cycorp IKB or full KB to work as setup below.
      if (choice.equals("all")) {
        exportDaml.includeUpwardClosure = false;
        exportDaml.title = "Open Cyc Ontology";
        exportDaml.outputPath = "open-cyc.daml";
        exportDaml.export(ExportDaml.EXPORT_ENTIRE_KB);
      }
      if (choice.equals("eeld-core")) {
        exportDaml.cycKbSubsetCollectionGuid = eeldSharedOntologyCoreConstantGuid;
        exportDaml.cycKbSubsetFilterGuid = ikbConstantGuid;
        exportDaml.title = "EELD Shared Core Ontology";
        exportDaml.outputPath = "eeld-shared-core-ontology.daml";
        exportDaml.export(ExportDaml.EXPORT_KB_SUBSET);
      } else if (choice.equals("eeld")) {
        exportDaml.cycKbSubsetCollectionGuid = eeldSharedOntologyConstantGuid;
        exportDaml.cycKbSubsetFilterGuid = ikbConstantGuid;
        exportDaml.title = "EELD Shared Ontology";
        exportDaml.outputPath = "eeld-shared-ontology.daml";
        CycList kbSubsetCollections = new CycList();
        kbSubsetCollections.add(cycAccess.getKnownConstantByName("EELDSyntheticDataConstant"));
        kbSubsetCollections.add(cycAccess.getKnownConstantByName("EELDNaturalDataConstant"));
        CycList applicableBinaryPredicates =
            cycAccess.getApplicableBinaryPredicates(kbSubsetCollections);
        applicableBinaryPredicates.remove(cycAccess.isa);
        applicableBinaryPredicates = applicableBinaryPredicates.sort();
        Log.current.println(
            "applicableBinaryPredicates: \n" + applicableBinaryPredicates.cyclify());
        exportDaml.applicableBinaryPredicates = applicableBinaryPredicates;
        exportDaml.export(ExportDaml.EXPORT_KB_SUBSET);

      } else if (choice.equals("transportation-device")) {
        Guid transportationDeviceGuid =
            CycObjectFactory.makeGuid("bd58d540-9c29-11b1-9dad-c379636f7270");
        exportDaml.rootTermGuid = transportationDeviceGuid;
        exportDaml.cycKbSubsetFilterGuid = counterTerrorismConstantGuid;
        exportDaml.export(ExportDaml.EXPORT_KB_SUBSET_BELOW_TERM);
      } else {
        System.out.println("specified choice not found - " + choice);
        System.exit(1);
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  }
Exemplo n.º 4
0
 /** Demonstrates getArgNGenls api function. */
 protected void demo8() throws IOException, UnknownHostException, CycApiException {
   Log.current.println("Demonstrating getArgNGenls api function.\n");
   CycList argNGenls =
       cycAccess.getArgNGenls(cycAccess.getKnownConstantByName("skillCapableOf"), 2);
   Log.current.println("\nThe obtained getArgNGenls are:\n" + argNGenls.cyclify());
 }
Exemplo n.º 5
0
 /** Demonstrates arg1Isas api function. //subject Type取得 */
 protected void demo7() throws IOException, UnknownHostException, CycApiException {
   Log.current.println("Demonstrating arg1Isas api function.\n");
   CycList arg1Isas = cycAccess.getArg1Isas(cycAccess.getKnownConstantByName("performedBy"));
   Log.current.println("\nThe obtained arg1Isas are:\n" + arg1Isas.cyclify());
 }
Exemplo n.º 6
0
 /** Demonstrates getGenls api function. //Type 取得 */
 protected void demo5() throws IOException, UnknownHostException, CycApiException {
   Log.current.println("Demonstrating getGenls api function.\n");
   CycList genls = cycAccess.getGenls(cycAccess.getKnownConstantByName("Dog"));
   Log.current.println("\nThe obtained direct genls are:\n" + genls.cyclify());
 }
Exemplo n.º 7
0
 /** 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());
 }
Exemplo n.º 8
0
  // 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.");
  }