PROLOG Selecting only one answer of multiple possibilities

时间:2017-04-24 17:30:52

标签: prolog

I have a code like this:

op:-
   keyword(a),
   write('Answer A'), nl.
op:-
   keyword(a),
   keyword(b),
   write('Answer A and B'), nl.
op:-
   keyword(a),
   keyword(b),
   keyword(c)
   write('Answer A, B and C'), nl.

Keywords provide details into the answer that must be used, problem is. I want the answer to be as specific as possible and provide only ONE. In this case, if I got both keyword a, b and c, I would get:

Answer A.

Answer A and B.

Answer A, B and C.

But what Id like to get is just:

Answer A, B and C.

¿How is the correct way to achieve this?

1 个答案:

答案 0 :(得分:-1)

正确的方法是添加不适用条件的否定:

private String calculateSecretHash(@Nonnull String userName) {

  SecretKeySpec signingKey = new SecretKeySpec(m_clientSecret.getBytes(StandardCharsets.UTF_8), HmacAlgorithms.HMAC_SHA_256.toString());
  try {
    Mac mac = Mac.getInstance(HmacAlgorithms.HMAC_SHA_256.toString());
    mac.init(signingKey);
    mac.update(userName.getBytes(StandardCharsets.UTF_8));
    byte[] rawHmac = mac.doFinal(m_clientId.getBytes(StandardCharsets.UTF_8));
    return Base64.encodeBase64String(rawHmac);

  } catch (Exception ex) {
    throw new PgkbRuntimeException("Error calculating secret hash", ex);
  }
}

或者您可以使用if-then-else:

op :-
  keyword(a),
  not keyword(b),
  not keyword(c),
  write('Answer A'), nl.
op :-
  keyword(a),
  keyword(b),
  not keyword(c),
  write('Answer A and B'), nl.
op :-
  keyword(a),
  keyword(b),
  keyword(c)
  write('Answer A, B and C'), nl.