当前位置: 首页>>代码示例>>Python>>正文


Python Prolog.dynamic方法代码示例

本文整理汇总了Python中pyswip.Prolog.dynamic方法的典型用法代码示例。如果您正苦于以下问题:Python Prolog.dynamic方法的具体用法?Python Prolog.dynamic怎么用?Python Prolog.dynamic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyswip.Prolog的用法示例。


在下文中一共展示了Prolog.dynamic方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_issue_4

# 需要导入模块: from pyswip import Prolog [as 别名]
# 或者: from pyswip.Prolog import dynamic [as 别名]
    def test_issue_4(self):
        """
       	Patch for a dynamic method

        Ensures that the patch is working.

        https://code.google.com/p/pyswip/issues/detail?id=4
        """

        from pyswip import Prolog
        
        Prolog.dynamic('test_issue_4_d/1')
        Prolog.assertz('test_issue_4_d(test1)')
        Prolog.assertz('test_issue_4_d(test1)')
        Prolog.assertz('test_issue_4_d(test1)')
        Prolog.assertz('test_issue_4_d(test2)')
        results = list(Prolog.query('test_issue_4_d(X)'))
        self.assertEqual(len(results), 4)
        
        Prolog.retract('test_issue_4_d(test1)')
        results = list(Prolog.query('test_issue_4_d(X)'))
        self.assertEqual(len(results), 3)
        
        Prolog.retractall('test_issue_4_d(test1)')
        results = list(Prolog.query('test_issue_4_d(X)'))
        self.assertEqual(len(results), 1)
开发者ID:swenzel,项目名称:pyswip3,代码行数:28,代码来源:test_issues.py

示例2: question_finder

# 需要导入模块: from pyswip import Prolog [as 别名]
# 或者: from pyswip.Prolog import dynamic [as 别名]
def question_finder(question, ans):
  p = Prolog()
  p.consult('/home/jordanhudgens/code/coderprofile/survey/knowledgebase.pl')            # When placed on server, be sure to change this path!!!!
  
  # Question 1:  Type of Projects Desired to Learn
  if question == "What type of projects do you want to learn how to build?":
    p.dynamic('projectdesired/1')      ## To account for going back
    p.retractall('projectdesired(_)')  ## To account for going back
    if ans == "iPhone App":
      p.assertz('projectdesired(iphoneapp)')
    if ans == "Android App":
      p.assertz('projectdesired(androidapp)')
    if ans == "Web Application":
      p.assertz('projectdesired(webapp)') 
    if ans == "Front End Website Development":
      p.assertz('projectdesired(frontend)') 
    if ans == "just programming":
      p.assertz('projectdesired(generalprogramming)')
  
  # Question 2:  Budget
  if question == "What is your budget?":
    p.dynamic('budget/1')      ## To account for going back
    p.retractall('budget(_)')  ## To account for going back
    if ans == "$0":
      p.assertz('budget(0)')
    if ans == "$50-$250":
      p.assertz('budget(250)')
    if ans == "$251-$500":
      p.assertz('budget(500)') 
    if ans == "$501-$1000":
      p.assertz('budget(1000)')
    if ans == "$1001-$1500":
      p.assertz('budget(1500)') 
    if ans == "$1501+":
      p.assertz('budget(1000000)') 
      
  # Question 3:  Level of Education
  if question == "What is the highest level of education you've completed?":
    p.dynamic('education/1')      ## To account for going back
    p.retractall('education(_)')  ## To account for going back
    if ans == "High School":
      p.assertz('education(highschool)')
    if ans == "Associates":
      p.assertz('education(associates)')
    if ans == "Bachelors":
      p.assertz('education(bachelors)') 
    if ans == "Graduate":
      p.assertz('education(graduate)')
      
  # Question 4:  Programming Experience
  if question == "What programming experience do you have?":
    p.dynamic('experience/1')      ## To account for going back
    p.retractall('experience(_)')  ## To account for going back
    if ans == "None":
      p.assertz('experience(none)')
    if ans == "Low":
      p.assertz('experience(low)')
    if ans == "Intermediate":
      p.assertz('experience(intermediate)') 
    if ans == "Extensive":
      p.assertz('experience(extensive)')
  
  # Question 5:  Learning Priority
  if question == "What's more of a priority for you to learn?":
    p.dynamic('priority/1')      ## To account for going back
    p.retractall('priority(_)')  ## To account for going back
    if ans == "Theory of coding":
      p.assertz('priority(theory)')
    if ans == "Real life projects":
      p.assertz('priority(practical)')
  
  # Question 6:  Employment Status
  if question == "Are you currently employed full time?":
    p.dynamic('employment/1')      ## To account for going back
    p.retractall('employment(_)')  ## To account for going back
    if ans == "Yes":
      p.assertz('employment(fulltime)')
    if ans == "No":
      p.assertz('employment(none)')
  
  # Question 7:  Weekly Time Dedication
  if question == "How many hours can you dedicate to learning each week?":
    p.dynamic('hoursfree/1')      ## To account for going back
    p.retractall('hoursfree(_)')  ## To account for going back
    if ans == "5":
      p.assertz('hoursfree(5)')
    if ans == "6-10":
      p.assertz('hoursfree(10)')
    if ans == "11-20":
      p.assertz('hoursfree(20)') 
    if ans == "21-30":
      p.assertz('hoursfree(30)')
    if ans == "31-40":
      p.assertz('hoursfree(40)') 
    if ans == "40+":
      p.assertz('hoursfree(168)') 
  
  # Question 8:  Feature Driven Developer
  if question == "Do you like to see the potential features you're going to build before learning how to implement them?":
    p.dynamic('featuredriven/1')      ## To account for going back
#.........这里部分代码省略.........
开发者ID:jordanhudgens,项目名称:coderprofile,代码行数:103,代码来源:pfunctions.py


注:本文中的pyswip.Prolog.dynamic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。