本文整理汇总了Java中edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant类的典型用法代码示例。如果您正苦于以下问题:Java LogicalConstant类的具体用法?Java LogicalConstant怎么用?Java LogicalConstant使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LogicalConstant类属于edu.cornell.cs.nlp.spf.mr.lambda包,在下文中一共展示了LogicalConstant类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant; //导入依赖的package包/类
/**
* Populates the list of mainPredicates, along with mapping of variables in
* the lambda expression to potential sources from which they might have been
* originated.
*
* @param mainPredicates
* @param varToEvents
* @param varToEntities
* @param sentence
* @param parse
*/
private static void process(List<Literal> mainPredicates,
Map<Term, List<Integer>> varToEvents,
Map<Term, List<Integer>> varToEntities, Map<Term, List<Term>> varToConj,
List<Pair<Term, Term>> equalPairs, Sentence sentence,
LogicalExpression parse) {
if (parse instanceof Lambda) {
process(mainPredicates, varToEvents, varToEntities, varToConj,
equalPairs, sentence, ((Lambda) parse).getBody());
} else if (parse instanceof Literal) {
if (((LogicalConstant) ((Literal) parse).getPredicate()).getBaseName()
.startsWith("p_")) {
mainPredicates.add(((Literal) parse));
processPredicate(((Literal) parse), varToEvents, varToEntities,
varToConj, equalPairs);
} else {
for (int i = 0; i < ((Literal) parse).numArgs(); i++) {
process(mainPredicates, varToEvents, varToEntities, varToConj,
equalPairs, sentence, ((Literal) parse).getArg(i));
}
}
}
}
示例2: setConstants
import edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant; //导入依赖的package包/类
public GenerationRepositoryWithConstants setConstants(
Set<LogicalConstant> constants) {
final long startTime = System.currentTimeMillis();
long aggregate = 0;
final Map<FactoringSignature, List<List<LogicalConstant>>> signaturesAndSeqs = new HashMap<FactoringSignature, List<List<LogicalConstant>>>();
for (final FactoringSignature signature : signatures) {
final List<List<LogicalConstant>> seqs = Collections
.unmodifiableList(
createPotentialConstantSeqs(constants, signature));
aggregate += seqs.size();
signaturesAndSeqs.put(signature, seqs);
}
LOG.debug(
"Initialized generation repository with %d constants sequences (%.3fsec)",
aggregate, (System.currentTimeMillis() - startTime) / 1000.0);
return new GenerationRepositoryWithConstants(constants, templates,
templatesAndAttributes, attributes, signaturesAndSeqs);
}
示例3: AMRServices
import edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant; //导入依赖的package包/类
private AMRServices(String skolemPredicateBaseName, Type textType,
String refPredicateBaseName, SpecificationMapping mapping,
File stanfordModelFile, String opPredicatePrefix,
LogicalConstant dummyEntity, LogicalConstant nameInstancePredicate,
Type typingPredicateType, IllinoisNERWrapper namedEntityRecognizer,
File propBankDir) throws IOException {
this.opPredicatePrefix = opPredicatePrefix;
this.dummyEntity = dummyEntity;
this.nameInstancePredicate = nameInstancePredicate;
this.typingPredicateType = typingPredicateType;
this.namedEntityRecognizer = namedEntityRecognizer;
// Add a lemmatizer that simply returns the lower-cased word.
this.lemmatizer = new UnionLemmatizer(new WordNetLemmatizer(),
word -> SetUtils.createSingleton(word.toLowerCase()));
this.skolemPredicateBaseName = skolemPredicateBaseName;
this.textType = textType;
this.refPredicateBaseName = refPredicateBaseName;
this.mapping = mapping;
this.tagger = stanfordModelFile == null ? null
: new MaxentTagger(stanfordModelFile.getAbsolutePath());
this.propBank = propBankDir == null ? null : new PropBank(propBankDir);
}
示例4: isCoordinator
import edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant; //导入依赖的package包/类
private boolean isCoordinator(LogicalExpression predicate, int numArgs) {
if (predicate instanceof LogicalConstant
&& (isConjunctionCoordinator((LogicalConstant) predicate) || isDisjunctionCoordinator((LogicalConstant) predicate))
&& predicate.getType() instanceof ComplexType) {
final ComplexType predicateType = (ComplexType) predicate.getType();
Type current = predicateType;
int count = 0;
while (current instanceof ComplexType) {
++count;
current = ((ComplexType) current).getRange();
}
return count == numArgs;
} else {
return false;
}
}
示例5: read
import edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant; //导入依赖的package包/类
public LogicalExpression read(String amr) throws IOException {
try (StringReader reader = new StringReader(amr)) {
final String firstToken = getNextToken(reader);
if (!firstToken.equals("(")) {
throw new IllegalStateException("AMR doesn't start with '(': "
+ amr);
}
final Map<LogicalConstant, Pair<SkolemId, Type>> skolemIDs = new HashMap<>();
final LogicalExpression instance = parseInstance(reader,
new HashMap<String, Variable>(), skolemIDs);
// Replace all dummy logical constants with the proper skolem IDs.
final SetReferences visitor = new SetReferences(skolemIDs);
visitor.visit(instance);
return visitor.tempReturn;
}
}
示例6: read
import edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant; //导入依赖的package包/类
/**
* Given a string, read a lexeme from it.
*/
public static Lexeme read(String line, String origin) {
final String[] split = line.split(" :: ", 3);
final String[] constantsSplit = split[1].split(", ");
final List<LogicalConstant> constants = new ArrayList<LogicalConstant>(
constantsSplit.length);
for (final String constant : constantsSplit) {
constants.add(LogicalConstant.read(constant));
}
final String[] attributesSplit = split[2].split(", ");
final List<String> attributes = new ArrayList<String>(
attributesSplit.length);
for (final String attribute : attributesSplit) {
attributes.add(attribute);
}
return new Lexeme(TokenSeq.of(split[0].split(" ")), constants,
attributes, origin == null ? new HashMap<String, String>()
: MapUtils.createSingletonMap(
LexicalEntry.ORIGIN_PROPERTY, origin));
}
示例7: apply
import edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant; //导入依赖的package包/类
@Override
public ParseRuleResult<LogicalExpression> apply(
Category<LogicalExpression> category, SentenceSpan span) {
if (isValidArgument(category, span)) {
final Pair<Lambda, LogicalConstant> pair = DummyEntityServices
.stripDummy((Lambda) category.getSemantics());
if (pair != null) {
final LogicalConstant inversedRelation = AMRServices
.makeRelationPassive(pair.second(), true);
if (inversedRelation != null) {
return new ParseRuleResult<>(name, Category.create(
targetSyntax, categoryServices.apply(
categoryServices.apply(helperCategory,
inversedRelation), pair.first())));
}
}
}
return null;
}
示例8: Lexeme
import edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant; //导入依赖的package包/类
public Lexeme(TokenSeq tokens, List<LogicalConstant> constants,
List<String> attributes, FactoringSignature signature,
Map<String, String> properties) {
assert signature != null;
assert tokens != null;
assert constants != null;
assert properties != null;
assert signature.equals(getSignature(constants,
signature.getNumAttributes()));
this.properties = Collections.unmodifiableMap(properties);
this.attributes = attributes;
this.constants = Collections.unmodifiableList(constants);
this.tokens = tokens;
this.signature = signature;
this.hashCodeCache = calcHashCode();
}
示例9: test5
import edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant; //导入依赖的package包/类
@Test
public void test5() {
final LogicalExpression exp = TestServices
.getCategoryServices()
.readSemantics(
"(lambda $0:<e,t> (lambda $1:e (and:<t*,t> (do:<e,<e,<e,t>>> roo:e $1 (a:<<e,t>,e> (lambda $0:e (boo:<e,<e,t>> $0 too:e)))) ($0 $1) (boo:<e,<e,t>> $1 goo:e))))");
final Result result = ExtractTypedSubExpression.of(exp, LogicalConstant
.read("p:t"), LogicLanguageServices.getTypeRepository()
.getTypeCreateIfNeeded("t"), true);
Assert.assertNotNull(result);
final LogicalExpression expectedSubExp = ((Literal) ((Lambda) ((Lambda) exp)
.getBody()).getBody()).getArg(0);
final LogicalExpression expectedRemainder = TestServices
.getCategoryServices()
.readSemantics(
"(lambda $0:<e,t> (lambda $1:e (and:<t*,t> p:t ($0 $1) (boo:<e,<e,t>> $1 goo:e))))");
Assert.assertEquals(expectedRemainder,
result.getExpressionWithPlaceholder());
Assert.assertEquals(expectedSubExp, result.getExtractedSubExpression());
}
示例10: evaluateConstant
import edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant; //导入依赖的package包/类
@Override
public Object evaluateConstant(LogicalConstant logicalConstant) {
// Try to treat the constant as a number
final Long num = LogicLanguageServices
.logicalExpressionToInteger(logicalConstant);
if (num != null) {
return new Double(num);
}
// Case true:t
if (LogicLanguageServices.getTrue().equals(logicalConstant)) {
return true;
}
// Case false:t
if (LogicLanguageServices.getFalse().equals(logicalConstant)) {
return false;
}
// Unknown constant
return null;
}
示例11: test1
import edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant; //导入依赖的package包/类
@Test
public void test1() {
final LogicalExpression exp = TestServices
.getCategoryServices()
.readSemantics(
"(lambda $0:<e,t> (lambda $1:e (and:<t*,t> ($0 $1) (boo:<e,<e,t>> $1 goo:e))))");
final Result result = ExtractTypedSubExpression.of(exp, LogicalConstant
.read("p:e"), LogicLanguageServices.getTypeRepository()
.getEntityType(), true);
Assert.assertNotNull(result);
final LogicalExpression expectedSubExp = TestServices
.getCategoryServices().readSemantics("goo:e");
final LogicalExpression expectedRemainder = TestServices
.getCategoryServices()
.readSemantics(
"(lambda $0:<e,t> (lambda $1:e (and:<t*,t> ($0 $1) (boo:<e,<e,t>> $1 p:e))))");
Assert.assertEquals(expectedRemainder,
result.getExpressionWithPlaceholder());
Assert.assertEquals(expectedSubExp, result.getExtractedSubExpression());
}
示例12: doFactoring
import edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant; //导入依赖的package包/类
private static List<Pair<List<LogicalConstant>, LexicalTemplate>> doFactoring(
final Category<LogicalExpression> inputCategory, boolean doMaximal,
boolean doPartial, int maxConstantsInPartial,
final Map<String, String> properties, final int numAttributes) {
if (inputCategory.getSemantics() == null) {
return ListUtils.createSingletonList(
Pair.of(Collections.<LogicalConstant> emptyList(),
new LexicalTemplate(
Collections.<LogicalConstant> emptyList(),
numAttributes, inputCategory, properties)));
}
final Set<Pair<AbstractConstants.Placeholders, ? extends LogicalExpression>> factoring = AbstractConstants
.of(inputCategory.getSemantics(), doMaximal, doPartial,
maxConstantsInPartial);
return factoring.stream()
.map(obj -> Pair
.of(Collections.unmodifiableList(obj.first().originals),
new LexicalTemplate(
Collections.unmodifiableList(
obj.first().placeholders),
numAttributes,
inputCategory.cloneWithNewSemantics(
obj.second()), properties)))
.collect(Collectors.toList());
}
示例13: visit
import edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant; //导入依赖的package包/类
@Override
public void visit(Literal literal) {
if (literal.getPredicate() instanceof LogicalConstant) {
if (!predicates.containsKey(literal.getPredicate())) {
predicates.put((LogicalConstant) literal.getPredicate(),
new Counter());
}
predicates.get(literal.getPredicate()).inc();
}
literal.getPredicate().accept(this);
final int len = literal.numArgs();
for (int i = 0; i < len; ++i) {
literal.getArg(i).accept(this);
}
}
示例14: read
import edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant; //导入依赖的package包/类
/**
* Given a string, read a lexical template from it.
*/
public static LexicalTemplate read(String line,
ICategoryServices<LogicalExpression> categoryServices, String origin) {
final int index = line.indexOf("-->");
final String constantsString = line.substring(1, index - 1);
final List<LogicalConstant> constants = new LinkedList<LogicalConstant>();
if (!constantsString.equals("")) {
for (final String constant : constantsString.split(", ")) {
constants.add(LogicalConstant.read(constant));
}
}
final String categoryString = line.substring(index + 3, line.length());
final Category<LogicalExpression> category = categoryServices
.read(categoryString);
return new LexicalTemplate(constants, category.getSyntax()
.getAttributes().size(), category, MapUtils.createSingletonMap(
LexicalEntry.ORIGIN_PROPERTY, origin));
}
示例15: apply
import edu.cornell.cs.nlp.spf.mr.lambda.LogicalConstant; //导入依赖的package包/类
@Override
public ParseRuleResult<LogicalExpression> apply(
Category<LogicalExpression> left,
Category<LogicalExpression> right, SentenceSpan span) {
final CoordinationSyntax unification = CoordinationServices
.unifyCategories(left, right);
if (unification != null) {
final Category<LogicalExpression> resultCategory = doApply(
ReplaceFreeVariablesIfPresent.of(left.getSemantics(), right
.getSemantics().getFreeVariables()),
(Literal) right.getSemantics(),
unification.getCoordinatedSyntax(),
(LogicalConstant) ((Literal) right.getSemantics())
.getPredicate());
if (resultCategory != null) {
return new ParseRuleResult<>(ruleName, resultCategory);
}
}
return null;
}