Generates a CCG category with head and dependency information
automatically populated from the syntactic category and
logical form. The logical form itself is used as the semantic
head of the returned category.

@param cat
@param logicalForm
@return
767250
public static CcgCategory fromSyntaxLf(HeadedSyntacticCategory cat, Expression2 lf) {
    String head = lf.toString();
    head = head.replaceAll(" ", "_");
    List<String> subjects = Lists.newArrayList();
    List<Integer> argumentNums = Lists.newArrayList();
    List<Integer> objects = Lists.newArrayList();
    
    List<HeadedSyntacticCategory> argumentCats = Lists.newArrayList(cat.getArgumentTypes());
    Collections.reverse(argumentCats);
    for (int i = 0; i < argumentCats.size(); i++) {
      subjects.add(head);
      argumentNums.add(i + 1);
      objects.add(argumentCats.get(i).getHeadVariable());
    }

    List<Set<String>> assignments = Lists.newArrayList();
    for (int i = 0; i < cat.getUniqueVariables().length; i++) {
      assignments.add(Collections.<String>emptySet());
    }
    int headVar = cat.getHeadVariable();
    assignments.set(headVar, Sets.newHashSet(head));

    return new CcgCategory(cat, lf, subjects, argumentNums, objects, assignments);
  }
154813
function (cats) {
  if (typeof cats === 'undefined') {
    cats = getCategories();
  }
  else if (Array.isArray(cats) === false) {
    cats = [cats];
  }
  return cats;
}
399575
private static void markEntityVars(HeadedSyntacticCategory cat, int[] uniqueVars,
      boolean[] isEntityVar) {
    if (cat.isAtomic()) {
      for (int var : cat.getUniqueVariables()) {
        int index = Ints.indexOf(uniqueVars, var);
        isEntityVar[index] = true;
      }
    } else {
      markEntityVars(cat.getArgumentType(), uniqueVars, isEntityVar);
      markEntityVars(cat.getReturnType(), uniqueVars, isEntityVar);
    }
  }
1315679
public HeadedSyntacticCategory getReturnType() {
    SyntacticCategory returnSyntax = syntacticCategory.getReturn();
    int[] returnSemantics = ArrayUtils.copyOf(semanticVariables, rootIndex);
    int returnRoot = returnSyntax.getNumReturnSubcategories();
    return new HeadedSyntacticCategory(returnSyntax, returnSemantics, returnRoot);
  }
1187442
private PortletDefinitionForm createNewPortletDefinitionForm() {
        final PortletDefinitionForm form = new PortletDefinitionForm();

        // pre-populate with top-level category
        final IEntityGroup portletCategoriesGroup =
                GroupService.getDistinguishedGroup(IPortletDefinition.DISTINGUISHED_GROUP);
        form.addCategory(
                new JsonEntityBean(
                        portletCategoriesGroup,
                        groupListHelper.getEntityType(portletCategoriesGroup)));

        // pre-populate with top-level group
        final IEntityGroup everyoneGroup =
                GroupService.getDistinguishedGroup(IPerson.DISTINGUISHED_GROUP);
        final JsonEntityBean everyoneBean =
                new JsonEntityBean(everyoneGroup, groupListHelper.getEntityType(everyoneGroup));
        form.setPrincipals(Collections.singleton(everyoneBean), true);

        return form;
    }
697881
protected void addTerm(NormalFormGCI term) {
        if (term instanceof NF1a) {
            final NF1a nf1 = (NF1a) term;
            final int a = nf1.lhsA();
            addTerms(ontologyNF1, a, nf1.getQueueEntry());
        } else if (term instanceof NF1b) {
            final NF1b nf1 = (NF1b) term;
            final int a1 = nf1.lhsA1();
            final int a2 = nf1.lhsA2();
            addTerms(ontologyNF1, a1, nf1.getQueueEntry1());
            addTerms(ontologyNF1, a2, nf1.getQueueEntry2());
        } else if (term instanceof NF2) {
            final NF2 nf2 = (NF2) term;
            addTerms(ontologyNF2, nf2);
        } else if (term instanceof NF3) {
            final NF3 nf3 = (NF3) term;
            addTerms(ontologyNF3, nf3);
        } else if (term instanceof NF4) {
            ontologyNF4.add((NF4) term);
        } else if (term instanceof NF5) {
            ontologyNF5.add((NF5) term);
        } else if (term instanceof NF6) {
            reflexiveRoles.add(((NF6) term).getR());
        } else if (term instanceof NF7) {
            final NF7 nf7 = (NF7) term;
            addTerms(ontologyNF7, nf7);
        } else if (term instanceof NF8) {
            final NF8 nf8 = (NF8) term;
            addTerms(ontologyNF8, nf8);
        } else {
            throw new IllegalArgumentException("Type of " + term
                    + " must be one of NF1 through NF8");
        }
    }
461501
protected final DataTable buildAggregationReport(F form) throws TypeMismatchException {
        // Pull data out of form for per-group fetching
        final AggregationInterval interval = form.getInterval();
        final DateMidnight start = form.getStart();
        final DateMidnight end = form.getEnd();

        final DateTime startDateTime = start.toDateTime();
        // Use a query end of the end date at 23:59:59
        final DateTime endDateTime = end.plusDays(1).toDateTime().minusSeconds(1);

        // Get the list of DateTimes used on the X axis in the report
        final List<DateTime> reportTimes =
                this.intervalHelper.getIntervalStartDateTimesBetween(
                        interval, startDateTime, endDateTime, maxIntervals);

        final Map<D, SortedSet<T>> groupedAggregations = createColumnDiscriminatorMap(form);

        // Determine the ValueType of the date/time column. Use the most specific column type
        // possible
        final ValueType dateTimeColumnType;
        if (interval.isHasTimePart()) {
            // If start/end are the same day just display the time
            if (startDateTime.toDateMidnight().equals(endDateTime.toDateMidnight())) {
                dateTimeColumnType = ValueType.TIMEOFDAY;
            }
            // interval has time data and start/end are on different days, show full date time
            else {
                dateTimeColumnType = ValueType.DATETIME;
            }
        }
        // interval is date only
        else {
            dateTimeColumnType = ValueType.DATE;
        }

        // Setup the date/time column description
        final ColumnDescription dateTimeColumn;
        switch (dateTimeColumnType) {
            case TIMEOFDAY:
                {
                    dateTimeColumn = new ColumnDescription("time", dateTimeColumnType, "Time");
                    break;
                }
            default:
                {
                    dateTimeColumn = new ColumnDescription("date", dateTimeColumnType, "Date");
                }
        }

        final DataTable table = new JsonDataTable();
        table.addColumn(dateTimeColumn);

        // Setup columns in the DataTable
        final Set<D> columnGroups = groupedAggregations.keySet();
        for (final D columnMapping : columnGroups) {
            final Collection<ColumnDescription> columnDescriptions =
                    this.getColumnDescriptions(columnMapping, form);
            table.addColumns(columnDescriptions);
        }

        // Query for all aggregation data in the time range for all groups.  Only the
        // interval and discriminator data is used from the keys.
        final Set<K> keys = createAggregationsQueryKeyset(columnGroups, form);
        final BaseAggregationDao<T, K> baseAggregationDao = this.getBaseAggregationDao();
        final Collection<T> aggregations =
                baseAggregationDao.getAggregations(
                        startDateTime, endDateTime, keys, extractGroupsArray(columnGroups));

        // Organize the results by group and sort them chronologically by adding them to the sorted
        // set
        for (final T aggregation : aggregations) {
            final D discriminator = aggregation.getAggregationDiscriminator();
            final SortedSet<T> results = groupedAggregations.get(discriminator);
            results.add(aggregation);
        }

        // Build Map from discriminator column mapping to result iterator to allow putting results
        // into
        // the correct column AND the correct time slot in the column
        Comparator<? super D> comparator = getDiscriminatorComparator();
        final Map<D, PeekingIterator<T>> groupedAggregationIterators =
                new TreeMap<D, PeekingIterator<T>>((comparator));
        for (final Entry<D, SortedSet<T>> groupedAggregationEntry :
                groupedAggregations.entrySet()) {
            groupedAggregationIterators.put(
                    groupedAggregationEntry.getKey(),
                    Iterators.peekingIterator(groupedAggregationEntry.getValue().iterator()));
        }

        /*
         * populate the data, filling in blank spots. The full list of interval DateTimes is used to create every row in the
         * query range. Then the iterator
         */
        for (final DateTime rowTime : reportTimes) {
            // create the row
            final TableRow row = new TableRow();

            // add the date to the first cell
            final Value dateTimeValue;
            switch (dateTimeColumnType) {
                case DATE:
                    {
                        dateTimeValue =
                                new DateValue(
                                        rowTime.getYear(),
                                        rowTime.getMonthOfYear() - 1,
                                        rowTime.getDayOfMonth());
                        break;
                    }
                case TIMEOFDAY:
                    {
                        dateTimeValue =
                                new TimeOfDayValue(
                                        rowTime.getHourOfDay(), rowTime.getMinuteOfHour(), 0);
                        break;
                    }
                default:
                    {
                        dateTimeValue =
                                new DateTimeValue(
                                        rowTime.getYear(),
                                        rowTime.getMonthOfYear() - 1,
                                        rowTime.getDayOfMonth(),
                                        rowTime.getHourOfDay(),
                                        rowTime.getMinuteOfHour(),
                                        0,
                                        0);
                        break;
                    }
            }
            row.addCell(new TableCell(dateTimeValue));

            for (final PeekingIterator<T> groupedAggregationIteratorEntry :
                    groupedAggregationIterators.values()) {
                List<Value> values = null;

                if (groupedAggregationIteratorEntry.hasNext()) {
                    final T aggr = groupedAggregationIteratorEntry.peek();
                    if (rowTime.equals(aggr.getDateTime())) {
                        // Data is for the correct time slot, advance the iterator
                        groupedAggregationIteratorEntry.next();

                        values = createRowValues(aggr, form);
                    }
                }

                // Gap in the data, fill it in using a null aggregation
                if (values == null) {
                    values = createRowValues(null, form);
                }

                // Add the values to the row
                for (final Value value : values) {
                    row.addCell(value);
                }
            }

            table.addRow(row);
        }

        return table;
    }
819702
public String getCat() {
    if (CoordinationElement_Type.featOkTst && ((CoordinationElement_Type)jcasType).casFeat_cat == null)
      jcasType.jcas.throwFeatMissing("cat", "de.julielab.jules.types.CoordinationElement");
    return jcasType.ll_cas.ll_getStringValue(addr, ((CoordinationElement_Type)jcasType).casFeatCode_cat);}
65167
public WordForm getDep() {
    if (Dependency_Type.featOkTst && ((Dependency_Type)jcasType).casFeat_dep == null)
      jcasType.jcas.throwFeatMissing("dep", "com.digitalpebble.rasp.Dependency");
    return (WordForm)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((Dependency_Type)jcasType).casFeatCode_dep)));}
196928
boolean rule2(final IFactory factory, final Inclusion[] gcis) {
        boolean result = false;

        if (lhs instanceof Conjunction) {
            Conjunction conjunction = (Conjunction) lhs;
            final AbstractConcept[] concepts = conjunction.getConcepts();

            if (concepts.length == 1) {
                // unwrap redundant conjuncts
                gcis[0] = new GCI(concepts[0], rhs);
                result = true;
            } else if (concepts.length == 0) {
                log.warn("Empty conjunct detected in: " + this);
                gcis[0] = new GCI(IFactory.TOP_CONCEPT, rhs);
                result = true;
            } else {
                // Swap out any non-Concept concepts (ie Existentials)
                for (int i = 0; !result && i < concepts.length; i++) {
                    if (!(concepts[i] instanceof Concept)) {
                        final Concept a = getA(factory, concepts[i]);
                        gcis[0] = new GCI(concepts[i], a);

                        final AbstractConcept[] newConcepts = new AbstractConcept[concepts.length];
                        System.arraycopy(concepts, 0, newConcepts, 0,
                                concepts.length);
                        newConcepts[i] = a;
                        gcis[1] = new GCI(new Conjunction(newConcepts), rhs);
                        result = true;
                    }
                }

                if (!result) {
                    if (concepts.length > 2) {
                        // Binarise a conjunction of Concepts (expected/assumed
                        // by NF1)
                        result = true;
                        final AbstractConcept[] newConcepts = new AbstractConcept[concepts.length - 1];
                        System.arraycopy(concepts, 1, newConcepts, 0,
                                concepts.length - 1);
                        final AbstractConcept d = new Conjunction(newConcepts);
                        final Concept a = getA(factory, d);
                        final AbstractConcept cAndA = new Conjunction(
                                new AbstractConcept[] { concepts[0], a });

                        gcis[0] = new GCI(cAndA, rhs);
                        gcis[1] = new GCI(d, a);
                    } else if (concepts.length < 2) {
                        throw new AssertionError(
                                "Conjunctions of fewer than "
                                        + "two elements should not exist at this point: "
                                        + this);
                    }
                }
            }
        }

        return result;
    }
947995
public static List<GrammaticalStructure> readCoNLLXGrammaticStructureCollection(String fileName, Map<String, GrammaticalRelation> shortNameToGRel, GrammaticalStructureFromDependenciesFactory factory) throws IOException {
    LineNumberReader reader = new LineNumberReader(new FileReader(fileName));
    List<GrammaticalStructure> gsList = new LinkedList<GrammaticalStructure>();

    List<List<String>> tokenFields = new ArrayList<List<String>>();

    for (String inline = reader.readLine(); inline != null;
         inline = reader.readLine()) {
      if (!"".equals(inline)) {
        // read in a single sentence token by token
        List<String> fields = Arrays.asList(inline.split("\t"));
        if (fields.size() != CoNLLX_FieldCount) {
          throw new RuntimeException(String.format("Error (line %d): 10 fields expected but %d are present", reader.getLineNumber(), fields.size()));
        }
        tokenFields.add(fields);
      } else {
        if (tokenFields.isEmpty())
          continue; // skip excess empty lines

        gsList.add(buildCoNNLXGrammaticStructure(tokenFields, shortNameToGRel, factory));
        tokenFields = new ArrayList<List<String>>();
      }
    }

    return gsList;
  }
357554
@Override
	public CPOptionCategory create(long CPOptionCategoryId) {
		CPOptionCategory cpOptionCategory = new CPOptionCategoryImpl();

		cpOptionCategory.setNew(true);
		cpOptionCategory.setPrimaryKey(CPOptionCategoryId);

		String uuid = PortalUUIDUtil.generate();

		cpOptionCategory.setUuid(uuid);

		cpOptionCategory.setCompanyId(companyProvider.getCompanyId());

		return cpOptionCategory;
	}
878356
private Expression2 getPreUnaryLogicalForm() {
    if (isTerminal()) {
      Expression2 logicalForm = lexiconEntry.getCategory().getLogicalForm();
      return logicalForm;
    } else {
      Expression2 leftLogicalForm = left.getLogicalForm();
      Expression2 rightLogicalForm = right.getLogicalForm();

      return getCombinatorLogicalForm(leftLogicalForm, rightLogicalForm);
    }
  }
171156
public WordForm getHead() {
    if (Dependency_Type.featOkTst && ((Dependency_Type)jcasType).casFeat_head == null)
      jcasType.jcas.throwFeatMissing("head", "com.digitalpebble.rasp.Dependency");
    return (WordForm)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((Dependency_Type)jcasType).casFeatCode_head)));}
804059
private void generateRuleDependencyGraph(List<CQIE> program) {
		for (CQIE rule : program) {
			ruleDependencyGraph.addVertex(rule);
			Predicate headPred = rule.getHead().getFunctionSymbol();
			Set<DefaultEdge> ontgoingEdges = predicateDependencyGraph
					.outgoingEdgesOf(headPred);

			for (DefaultEdge e : ontgoingEdges) {
				Predicate edgeTarget = predicateDependencyGraph
						.getEdgeTarget(e);
				Collection<CQIE> rules = ruleIndex.get(edgeTarget);
				if (rules != null) {
					for (CQIE dependentRule : rules) {
						ruleDependencyGraph.addVertex(dependentRule);
						ruleDependencyGraph.addEdge(rule, dependentRule);
					}
				}
			}
		}
	}
259227
public List<SyntacticCategory> getArgumentList() {
    if (isAtomic()) {
      return Lists.newArrayList();
    } else {
      List<SyntacticCategory> args = getReturn().getArgumentList();
      args.add(getArgument());
      return args;
    }
  }
942139
public function get_dataset_definitions_category($form) {
        global $CFG, $DB;
        $datasetdefs = array();
        $lnamemax = 30;
        if (!empty($form->category)) {
            $sql = "SELECT i.*, d.*
                      FROM {question_datasets} d, {question_dataset_definitions} i
                     WHERE i.id = d.datasetdefinition AND i.category = ?";
            if ($records = $DB->get_records_sql($sql, array($form->category))) {
                foreach ($records as $r) {
                    if (!isset ($datasetdefs["{$r->name}"])) {
                        $datasetdefs["{$r->name}"] = $r->itemcount;
                    }
                }
            }
        }
        return $datasetdefs;
    }