Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

類似度計算リファクタリング #58

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/ai-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This workflow enables developers to call PR-Agents `/[actions]` in PR's comments and upon PR creation.
# Learn more at https://www.codium.ai/pr-agent/
# This is v0.2 of this workflow file

name: PR-Agent

on:
pull_request:
types: [opened]
issue_comment:
types: [created]
workflow_dispatch:

permissions:
issues: write
pull-requests: write

jobs:
pr_agent_job:
runs-on: ubuntu-latest
name: Run pr agent on every pull request
if: ${{ github.event.sender.type != 'Bot' }}
steps:
- name: PR Agent action step
id: pragent
uses: Codium-ai/pr-agent@main
env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
# OPENAI_ORG: ${{ secrets.OPENAI_ORG }} # optional
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# PINECONE.API_KEY: ${{ secrets.PINECONE_API_KEY }}
# PINECONE.ENVIRONMENT: ${{ secrets.PINECONE_ENVIRONMENT }}
GITHUB_ACTION_CONFIG.AUTO_DESCRIBE: true
GITHUB_ACTION_CONFIG.AUTO_REVIEW: true
GITHUB_ACTION_CONFIG.AUTO_IMPROVE: true
PR_DESCRIPTION.EXTRA_INSTRUCTIONS: 'Please use Japanese.'
PR_REVIEWER.EXTRA_INSTRUCTIONS: 'Please use Japanese.'
PR_CODE_SUGGESTIONS.EXTRA_INSTRUCTIONS: 'Please use Japanese.'
Binary file modified simirality/__pycache__/main.cpython-311.pyc
Binary file not shown.
57 changes: 47 additions & 10 deletions simirality/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,71 @@ class Words(BaseModel):
assignmentWord: str
words: List[str]


@app.post("/similarity")
async def similarity(reqWords: Words):
assignmentWord = reqWords.assignmentWord
words = reqWords.words

try:
highscore, highscore_word = calcuSimilarity(assignmentWord, words)
except:
# 例外処理
print("Error: 類似度の計算に失敗しました。課題が存在しない可能性があります。")
return {"similarity": 0}

return {"similarity": highscore, "highscoreWord": highscore_word}

# 類似度の計算
def calcuSimilarity(assignmentWord, words):
assignmentWord_synset = wn.synset(f"{assignmentWord}.n.01")

highscore = 0
highscore_word = ""

for word in words:
print(f"word: {word}")
try:
word_synset = wn.synset(f"{word}.n.01")
similarity = assignmentWord_synset.wup_similarity(word_synset)
print(f"{word}: {similarity}")
similarity = calculate(assignmentWord_synset, word, assignmentWord)

if assignmentWord == word:
similarity = 1.0

if similarity is None:
print(f"'{assignmentWord}' と '{word}' の類似度を計算できません。")
print(f"similarity: {similarity}")

if similarity > highscore:
highscore = similarity
highscore_word = word
except:
print(f"Error: '{word}' はWordNetに存在しません。")

return {"similarity": highscore}
# WordNet にない形式を検索
wordByMorphy = wn.morphy(word)
print(f"wordByMorphy: {wordByMorphy}")
if wordByMorphy is not None:
try:
similarityByMorphy = calculate(assignmentWord_synset, wordByMorphy, assignmentWord)

print(f"similarity: {similarityByMorphy}")

if highscore < similarityByMorphy:
highscore = similarityByMorphy
highscore_word = word

except:
print(f"Error: '{word}' はWordNetに存在しません。")

return highscore, highscore_word

def calculate(assignmentWord_synset, word, assignmentWord):
if assignmentWord == word:
return 1.0

word_synset = wn.synset(f"{word}.n.01")

similarity = assignmentWord_synset.wup_similarity(word_synset)

if similarity is None:
print(f"'{assignmentWord}' と '{word}' の類似度を計算できません。")
return 0

return similarity


# MEMO こんな感じでPOSTリクエストを送る
Expand Down
Loading