code: public static CaduceusProgram read(@NonNull Resource resource) throws IOException {
        CaduceusProgram program = new CaduceusProgram();
  
        try (Reader reader = resource.reader()) {
           List<Object> rules = ensureList(new Yaml().load(reader), "Caduceus rules should be specified in a list");
  
           for (Object entry : rules) {
              Map<String, Object> ruleMap = ensureMap(entry, "Rule entry should be a map");
              String ruleName = Val.of(ruleMap.get("name")).asString();
              String pattern = Val.of(ruleMap.get("pattern")).asString();
              if (StringUtils.isNullOrBlank(pattern)) {
                 throw new IOException("No pattern specified: " + entry);
              }
              if (StringUtils.isNullOrBlank(ruleName)) {
                 throw new IOException("No rule name specified: " + entry);
              }
  
              List<CaduceusAnnotationProvider> annotationProviders = new LinkedList<>();
              if (ruleMap.containsKey("annotations")) {
                 List<Object> annotationList = ensureList(ruleMap.get("annotations"),
                                                          "Annotations should be specified as a list.");
                 for (Object o : annotationList) {
                    annotationProviders.add(CaduceusAnnotationProvider.fromMap(
                       ensureMap(o, "Annotation entries should be specified as a map."), resource.descriptor(),
                       ruleName));
                 }
              }
  
              List<CaduceusRelationProvider> relationProviders = new LinkedList<>();
              if (ruleMap.containsKey("relations")) {
                 List<Object> relations = ensureList(ruleMap.get("relations"),
                                                     "Relations should be specified as a list.");
                 for (Object o : relations) {
                    relationProviders.add(
                       CaduceusRelationProvider.fromMap(ensureMap(o, "Relation entries should be specified as a map.")));
                 }
              }
  
              try {
                 program.rules.add(new CaduceusRule(resource.descriptor(),
                                                    ruleName,
                                                    TokenRegex.compile(pattern),
                                                    annotationProviders,
                                                    relationProviders));
              } catch (ParseException e) {
                 throw new IOException("Invalid pattern for rule " + ruleName);
              }
  
           }
  
        }
        return program;
     }
docs: Read Caduceus program.
  
  @param resource the resource
  @return the lyre program
  @throws IOException the io exception